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;
    QProcess::startDetached(QString("C:\\Program Files (x86)\\Notepad++\\notedpad++.exe"));

  • Try...
    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->start(cmd, comandlist, QIODevice::ReadOnly);
      if (!process->waitForFinished()) {
        lstr = QString();
      } else {
        lstr = QString(process->readAll().constData());

  • Lifetime Qt Champion


    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\"");

  • Lifetime Qt Champion

    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 :)

  • @rafael

    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:

    1. QDesktopServices::openUrl(QUrl("file:///C:/windows/notepad", QUrl::TolerantMode));
    2.  system("C:/WINDOWS/system32/osk.exe");
    3.   QProcess::startDetached("\"C:\\Program Files\\WinHTTrack\\WinHTTrack.exe\"");
    4.  QString cmd = QString("\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\"");

    Hope this helps someone.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.