Event processing and orders



  • Hello,

    I want to have a connection timeout for QTcpSocket and have a few questions (also see pseudocode below):

    Will QObject::killTimer() drop any pending events of the passed timer?
    Meaning, is it guaranteed that no timerEvent() will occur after killTimer() was called?

    And is it possible that the QTcpSocket::connected() signal event is queued but before it is processed, other events (like timer events) can occur?

    Could the following happen?:
    The connection attempt succeeds, Qt internally queues the QTcpSocket::connected() signal event but by chance, the timerEvent() is called before SltConnected().
    So, OnConnected(false) is called but then, the qeueued connected-event is processed and OnConnected(true); is called, so I have two OnConnected() calls which I would like to avoid.

    Of course I could use a Qt::DirectConnection, but then again my question is if killTimer() inside Client::SltConnected() guarantees that Client::timerEvent() will not be called anymore (if it was possibly already queued).

    // Pseudocode
    
    connect(&socket, &QTcpSocket::connected, this, &Client::SltConnected, Qt::QueuedConnection);
    
    Client::Connect()
    {
        startTimer(1000);
        socket.connectToHost();
    }
    
    Client::SltConnected()
    {
        killTimer();
        OnConnected(true);
    }
    
    Client::timerEvent()
    {
        killTimer();
        socket.abort();
        OnConnected(false);
    }
    

    Thank you very much!



  • Pushing again.


Log in to reply
 

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