c++ - Command Line closing despite using QProcess::startDetached() -
i'm trying open server via batch file in cmd.exe in qt application. despite i'm using qprocess::startdetached() start command line closes after start. server starting, instead of "serving" process killed. here code:
void dicomreceiver::startreceiver() { qprocess receiver; boost::filesystem::path dbdir = boost::filesystem::absolute(databasedirectory.tostdstring()); receiver.startdetached("cmd.exe", qstringlist() << "/c" << "dcmrcv.bat" << "aetitle:11112" << "-dest " << dbdir.string().c_str()); receiver.waitforstarted(); }
when run batch file manually in cmd.exe working desired. have idea how keep process running can use server?
startdetached
static function. don't need process instance.you should pass working directory
startdetached
. know "closes" because batch file doesn't exist it's looking it.your
waitforstarted()
call no-op sincestartdetached
method not knowreceiver
instance. wrote obfuscated c++ deceives you. there no way wait detached process start when using qt. detached process fire-and-forget.do not use
waitforxxx
methods, block thread they're in, , make ui unresponsive. use signal-slot connections , write asynchronous code instead.
so, method should fixed follows:
void dicomreceiver::startreceiver() { boost::filesystem::path dbdir = boost::filesystem::absolute(databasedirectory.tostdstring()); // fixme const qstring batchpath = qstringliteral("/path/to/the/batch/file"); qprocess::startdetached("cmd.exe", qstringlist() << "/c" << "dcmrcv.bat" << "aetitle:11112" << "-dest " <<< dbdir.string().c_str(), batchpath); }
Comments
Post a Comment