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. Pauses/stop QObjects inside QThread event loop
QtWS25 Last Chance

Pauses/stop QObjects inside QThread event loop

Scheduled Pinned Locked Moved Unsolved General and Desktop
qobjectqthreadqeventloop
9 Posts 2 Posters 1.4k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 9 Nov 2019, 22:06 last edited by
    #1

    Hey

    I'm in need of pausing a certain QObject running in the QThread event loop so the object::event() does not fire. I want it to still receive events, but I don't want it to execute them until I unblock the loop...

    How can I do it ?

    Regards
    Dariusz

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Nov 2019, 22:27 last edited by
      #2

      Hi,

      What kind of event do you have in mind ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply 9 Nov 2019, 22:28
      0
      • S SGaist
        9 Nov 2019, 22:27

        Hi,

        What kind of event do you have in mind ?

        D Offline
        D Offline
        Dariusz
        wrote on 9 Nov 2019, 22:28 last edited by
        #3

        @SGaist said in Pauses/stop QObjects inside QThread event loop:

        Hi,

        What kind of event do you have in mind ?

        Well say I send 100k events to my Qobject. I would like to pause its event loop for a while and resume it later.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 9 Nov 2019, 22:30 last edited by
          #4

          How are you sending these events ? What do they trigger in your object ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dariusz
            wrote on 9 Nov 2019, 22:31 last edited by
            #5

            QObject::event() filters events it receives (which I send via qApp::postEvent(object,event);) and processes them accordingly. I was thinking I could do while(pause)QThread::msleep(1); in the QObject::Event(QEvent*e); but that feels... "bad"...

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 9 Nov 2019, 23:10 last edited by
              #6

              Again, can you explain why you are using events directly ?
              What are you doing in these objects ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dariusz
                wrote on 9 Nov 2019, 23:17 last edited by
                #7

                I'm using them to do the processing and control order of my work via Qevent/priority it provides. Qt don't send any events to it (as fara s I'm aware) so its just my processing unit.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Dariusz
                  wrote on 10 Nov 2019, 08:27 last edited by
                  #8

                  @SGaist Hey, any idea how to pause that event loop? Is it QObjects event loop or QThread Event loop that I need to pause?

                  Regards
                  Dariusz

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 10 Nov 2019, 19:38 last edited by
                    #9

                    QObject has no event loop, the event loop is in QCoreApplication and siblings.

                    You can not just stop the one from you main application. As for QThread you can interrupt the thread but I'm really not sure that's the best way to handle your situation.

                    From the looks of it, you seem to have to create a queue of the events received and store these there while in pause mode and then empty that queue on restart if that makes sense.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    2

                    9/9

                    10 Nov 2019, 19:38

                    • Login

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