Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Wait for QCopChannel Receive event



  • Hi,

    Following is the scenario:

    1> During application execution, at a point(a) my application sends some data to QCopChannel
    2> Application needs to wait for acknowledgement
    3> Process rest of the operation after acknowledgement
    

    Is there any way to get the required results? I have codded the following but facing two issues:
    1> Receiver does not receive data.
    2> My application is hang in this state.

        orvOk_R2 = false;
        SendMsgR1();
    
        while ( !orvOk_R2 )    //orvOk_R2 will be true if get R2 message received
        {
            //Wait for R2 
        }
    

    If i only use "SendMsgR1();" the receiver is receiving correct message.

    PS, I am working on QTopiaapplication.

    Thanks


  • Lifetime Qt Champion

    Hi,

    Bad idea, your blocking the event loop from processing events.

    You should rather use something like a state machine and the received to go further in your logic.



  • Hi @SGaist,

    I don't have much expertise to to use StateMachine api. I use the following code and its working but here I can not verify if the correct acknowledgement is received or its a bad acknowledgement.

        QEventLoop loop;
        QTimer timer;
        connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
        timer.start(1000);
        loop.exec();
    

    Any simple solution instead?

    Thanks



  • Hi @SGaist,
    I modified the code slightly and it worked, here is the code snippet for your expert advise:

        while ( !orvOk_R2 )
        {
            //Wait for R2 from AFC or timeout
            SendMsgR1();
            QEventLoop loop;
            QTimer timer;
            connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
            timer.start(1000);
            loop.exec();
        }
    

    Thanks



  • @Kashif if your issue is solved, please don't forget to mark your post as such. Thanks


Log in to reply