Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QObject::connect() vs thread

    General and Desktop
    connect thread qt5.5.0 threading
    3
    4
    1790
    Loading More Posts
    • 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
      Pogi last edited by

      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 Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • P
          Pogi last edited by

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

          1 Reply Last reply Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by

            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 Reply Quote 0
            • First post
              Last post