startDetached
is a static function. You don't need a process instance.You should pass a working directory to
startDetached
. For all I know it "closes" because the batch file doesn't exist where it's looking for it.Your
waitForStarted()
call is a no-op since thestartDetached
method does not know anything about yourreceiver
instance. You simply wrote obfuscated C++ that deceives you. There is no way to wait for a detached process to start when using Qt. A detached process is fire-and-forget.Do not use
waitForXxx
methods, as they block the thread they're in, and make the UI unresponsive. Use signal-slot connections and write asynchronous code instead.
So, your method should be fixed as 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);
}