Important: Please read the Qt Code of Conduct -

QProcess is started and continues with code too early

  • Currently working with a QProcess that launches and is then embedded into a larger program. Currently the launching of the program works, however it continues on with the code too quickly so the process cannot be found by FindWindow (windows API call).

    If I place the code below before i start to "find window" the process does work but it takes along time before it's ready to continue with the code (too long really about 15 or more seconds before it's ready and waitforfinished normally reports as failed but still launches the program and works after that point).

    Below is the QProcess code with the beginning of the FindWindow command.

    @ QApplication a(argc, argv);
    //QTimer t;
    QProcess *m_process = new QProcess();
    //m_process = new QProcess();
    QStringList arguments;
    arguments << "";

        qDebug("\nSuccess in starting Process = Mplayer");
        qDebug("\nFailed To start Process = Mplayer");
    WId id = (WId)FindWindow(L"CCTV",NULL);
    if (id)
        qDebug() << id;@

  • Lifetime Qt Champion

  • Lifetime Qt Champion


    waitForFinished is waiting that the application started with QProcess finishes. What you should rather use is waitForStarted

  • Hey SGaist,

    Yea sadly I tried that first and that is where I actually got the main problem of it starting too quickly (it would pass through waitforstarted and go straight for findwindow and would just fail to find the window ID with a runtime C error). Essentially the program needs to be able to launch this application then when it's present as a HWID then it should continued not before.

    Currently to resolve this problem using a timeout before findWindow is activated .But by using a timeout, the application becomes visible for a few milliseconds before it's embedded into he main application which I would of liked to avoid if possible(lowest I was able to get the timeout down to was 200 ms).

    Any ideas what this might be related to ?

    To give you an idea of the error received when using waitforstarted please see below.

    bq. Invalid parameter passed to C runtime function.
    Invalid parameter passed to C runtime function.
    ASSERT: "result.hwnd" in file qwindowswindow.cpp, line 555

Log in to reply