Solved QProcess wont run executable.
-
I used the code below to start a new process. It will not run the executable.
what am i missing?I have tried both
QProcess p; p.start(QString("C:\\Progra~2\\Notepad++\\notedpad++.exe"));
QProcess::startDetached(QString("C:\\Program Files (x86)\\Notepad++\\notedpad++.exe"));
-
Try...
http://doc.qt.io/qt-5/qdesktopservices.html
QDesktopServices::openUrl("app location"); or read regedit default txt editor...Or argument file for notedpad++.exe....
QStringList comandlist comandlist << filetoopen.txt QString cmd = QString("notepad.exe"); QProcess *process = new QProcess(this); process->setReadChannelMode(QProcess::MergedChannels); process->start(cmd, comandlist, QIODevice::ReadOnly); if (!process->waitForFinished()) { lstr = QString(); } else { lstr = QString(process->readAll().constData()); }
-
Hi,
Did you check the status code of the process for more information ?
-
thank found the answer now.
QString cmd = QString("\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\"");
-
Glad you found out and thanks for sharing !
Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)
-
I"m glad you found a solution. In case you have other areas, here's another way it works.
QDesktopServices::openUrl(QUrl("file:///C:/windows/notepad", QUrl::TolerantMode));
I've found out there are about 4 different ways to run exe programs. When one doesn't work, the other 3 will lol. At least one of them will anyway. Since I'm here, I'll list the four different ways that I've found for others that may have any similar issues:
-
QDesktopServices::openUrl(QUrl("file:///C:/windows/notepad", QUrl::TolerantMode));
-
system("C:/WINDOWS/system32/osk.exe");
-
QProcess::startDetached("\"C:\\Program Files\\WinHTTrack\\WinHTTrack.exe\"");
-
QString cmd = QString("\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\"");
Hope this helps someone.
-