Qued Connection not queing...



  • 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
    }
    }
    }
    @



  • 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)));
    @



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


  • Moderators

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



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



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



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


Log in to reply
 

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