Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess is started and continues with code too early
Qt 6.11 is out! See what's new in the release blog

QProcess is started and continues with code too early

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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;
    //t.start(2500);
    QProcess *m_process = new QProcess();
    //m_process = new QProcess();
    QStringList arguments;
    arguments << "";
    //m_process->setProgram("C:\Windows\system32\notepad.exe");
    //_process->setArguments(arguments);
    m_process->start("C:\Windows\system32\notepad.exe");
    //m_process->waitForFinished();

    if(m_process->waitForFinished())
    {
        qDebug("\nSuccess in starting Process = Mplayer");
    }
    else
    {
        qDebug("\nFailed To start Process = Mplayer");
    }
    
    WId id = (WId)FindWindow(L"CCTV",NULL);
    if (id)
        qDebug() << id;@
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      maybe this has more info ?
      http://qt-project.org/forums/viewthread/7331

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved