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?

  1. startdetached static function. don't need process instance.

  2. you should pass working directory startdetached. know "closes" because batch file doesn't exist it's looking it.

  3. your waitforstarted() call no-op since startdetached method not know receiver instance. wrote obfuscated c++ deceives you. there no way wait detached process start when using qt. detached process fire-and-forget.

  4. 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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -