Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Qued Connection not queing...

    General and Desktop
    4
    7
    1583
    Loading More Posts
    • 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.
    • S
      SavageTwinky last edited by

      I'm having a strange issue with a connection not working properly as a queed connection. The idea is that we need to kill an QProcess, start another process, then allow the program to run the exit function. The app exit processes only when used as direct but this causes an issue with calling the exit prematurely.

      @ // notify windows ce we started
      int main()
      {
      test s;

      return a.exec();
      

      }
      @

      test.cpp
      @
      #include "StdAfx.h"

      test::test(QObject *parent) :
      QObject(parent)
      {
      firstApp = new QProcess(this);
      ahurarun = new QProcess(this);

      // connect both exits to appExit
      connect(firstApp, SIGNAL(finished(int,QProcess::ExitStatus)),
      this, SLOT(appExit(int,QProcess::ExitStatus)),
      Qt::QueuedConnection);

          firstApp->start("some app");
      

      }

      void test::startSecondApp()
      {
      if(QProcess::Running == firstApp->state())
      {
      // politely ask app to close
      firstApp->terminate();
      // then kill it if it doesn't
      QTimer::singleShot(10000, firstApp, SLOT(kill()));
      firstApp->waitForFinished(15000);
      }

      secondApp->start("some app");
      if(!secondApp->waitForStarted(30000))
      {

      }
      }

      void test::appExit(int exitCode, QProcess::ExitStatus exitStatus)
      {
      if(QObject::sender() == firstApp)
      {
      qDebug() << "firstApp exited early with code=" << QString::number(exitCode);

      if(QProcess::Running != secondApp->state())
      {
      // display some error for the app if it wasn't us
      }
      }
      }
      @

      1 Reply Last reply Reply Quote 0
      • S
        SavageTwinky last edited by

        just to clarify

        this doesn't work
        @
        // connect both exits to appExit
        connect(firstApp, SIGNAL(finished(int,QProcess::ExitStatus)),
        this, SLOT(appExit(int,QProcess::ExitStatus)),
        Qt::QueuedConnection);
        @

        this does
        @
        // connect both exits to appExit
        connect(firstApp, SIGNAL(finished(int,QProcess::ExitStatus)),
        this, SLOT(appExit(int,QProcess::ExitStatus)));
        @

        1 Reply Last reply Reply Quote 0
        • D
          dbzhang800 last edited by

          Maybe you should register the QProcess::ExitStatus type using qRegisterMetaType before it can be used in queuedConnection.

          1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators last edited by

            there should be some output on the console in that case which tells you what went wrong.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply Reply Quote 0
            • S
              SavageTwinky last edited by

              Stupid question, why would i need to register QProcess::ExitStatus?

              Should it make a difference if I leave the arguments out?
              ie:
              @connect(firstApp, SIGNAL(finished()),
              this, SLOT(appExit()),
              Qt::QueuedConnection);
              @
              This doesn't work either..

              Also, my console is extremely limited, its on a WinCE device, and the only output I get is from my ::OutPutDebugStr(). (or something to that extent)

              1 Reply Last reply Reply Quote 0
              • S
                SavageTwinky last edited by

                I ended up making a funny work around

                I connected a finished(int,QPRocess::exitStatus) to a queuedFinish(int,QProcess::exitStatus)

                and emited a appDone(QProcess*,int) as a queued connection to appExit(QProcess*,int)

                1 Reply Last reply Reply Quote 0
                • A
                  andre last edited by

                  I think the QMetaType registration would have been the easier and cleaner solution...

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post