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. Event processing and orders
Qt 6.11 is out! See what's new in the release blog

Event processing and orders

Scheduled Pinned Locked Moved General and Desktop
eventordertimerqueued
2 Posts 1 Posters 1.6k 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.
  • Q Offline
    Q Offline
    qtacc32
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qtacc32
      wrote on last edited by
      #2

      Pushing again.

      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