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. Is signal-slot blocking.??
QtWS25 Last Chance

Is signal-slot blocking.??

Scheduled Pinned Locked Moved General and Desktop
7 Posts 7 Posters 9.9k 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.
  • A Offline
    A Offline
    aekam
    wrote on 8 Feb 2012, 06:16 last edited by
    #1

    suppose i create an object of a class which has a slot. i connect this slot to any system signal like say readyRead() in constructor.

    can the execution of signal-slot, block my calling function, where i created instance of the class.??

    If you take care of inches, you won't have to worry about miles... :)

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on 8 Feb 2012, 07:15 last edited by
      #2

      Not sure, are you asking if the constructor could block on processing a signal? I think this could happen if you have a multithreaded application (therefore signals are coming independently from the thread that is building the instance).
      "This":http://developer.qt.nokia.com/doc/qt-4.8/threads-qobject.html could help.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on 8 Feb 2012, 08:41 last edited by
        #3

        Can you please rephrase your question. It is completely incomprehensible (to me).

        There is no way a slot connected in the constructor is execute before the constructor is finished, neither in single-threaded applications (the thread is executing your constructor) nor in multithreaded applications (the signal is dispatched as soon as the execution returns to the event loop, which happens in any case after the constructor has returned).

        I see this only happening if you <code>qApp->processEvents()</code> or <code>moveToThread(this)</code> in your constructor - both highly questionable. Rule of thumb: just don't do it.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shoyeb
          wrote on 8 Feb 2012, 08:48 last edited by
          #4

          no, this will not block the execution of your program.

          There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            miroslav
            wrote on 8 Feb 2012, 10:59 last edited by
            #5

            If the question is whether emitting a signal blocks the caller until the slots have been called, then the correct answer is "it depends".

            In a single-threaded case, signal-slot connections are direct connections, meaning the slots get called when the signal is emitted (the signal function is called). The signal method returns after all connected slots have been called. In a multi-threaded case, it depends on whether the sender and receiver are associated with the same thread.

            Have a look at http://doc.qt.nokia.com/4.7-snapshot/thread-basics.html for more details.

            Mirko Boehm | mirko@kde.org | KDE e.V.
            FSFE Fellow
            Qt Certified Specialist

            1 Reply Last reply
            1
            • K Offline
              K Offline
              kinjalp
              wrote on 10 Feb 2012, 12:07 last edited by
              #6

              please explained your problem in detail.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on 10 Feb 2012, 19:05 last edited by
                #7

                miroslav is right, but I guess the more correct answer is: it depends on what connection flag you used when you connected the signal and the slot. The default flag will result in different behaviour in threaded and non-threaded cases.

                1 Reply Last reply
                0

                1/7

                8 Feb 2012, 06:16

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved