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. QObject::connect() vs thread
QtWS25 Last Chance

QObject::connect() vs thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
connectthreadqt5.5.0threading
4 Posts 3 Posters 2.2k Views
  • 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.
  • P Offline
    P Offline
    Pogi
    wrote on last edited by
    #1

    can i use QOjbect::connect() for threading purpose?
    for example:

    this code:
    connect(timer,SIGNAL(timeout()),this,SLOT(receiveMessage()));
    timer->start(0);
    will execute receiveMessage() function everytime timeout signal is emitted.

    i understand signals and slot mechanism well. but my question is bugging me

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Your question is not clear.
      What do you want to do?
      In your timer example there is no extra thread involved.
      You can use signals/slots across threads, you just should use Qt::QueuedConnection in connect(...).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Pogi
        wrote on last edited by
        #3

        i mean, connect() will just act as thread while the slots function is non blocking

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          There's no multi-threading involved here whatsoever. All code here runs in a single thread (unless the timer object and "this" actually live in different threads).

          There's an event loop running in your app and timer events are just the same as any other. They get put in a queue and processed one after another.
          The above will basically mean that your slot is run every time Qt processes messages. It can have very bad influence on your app responsiveness if what you do in the slot is heavy.

          The most obvious question is: if you want a thread why not use an actual QThread instead of emulating it like that?

          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