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. Passing QFlags between threads
Qt 6.11 is out! See what's new in the release blog

Passing QFlags between threads

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 1.9k Views 3 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.
  • I Offline
    I Offline
    iw2lsi
    wrote on last edited by kshegunov
    #1

    Dear all,

    using Qt4.8.7, I'm in trouble trying to connect a signal to a slot on a different thread when signal/slot argument contains a QFlags...

    first of all... is this possible at all ?

    I'm declaring my flags as usual, with

       Q_DECLARE_FLAGS (ACTRLFLAGS, ACTRLFLAG) 
    

    and

        Q_DECLARE_OPERATORS_FOR_FLAGS( NMyClass::ACTRLFLAGS )
    

    but this seems not enougth when the connection is (queued) between threads... then I've try registering the type with

       Q_DECLARE_METATYPE(NMyClass::ACTRLFLAGS)
    

    and

      qRegisterMetaType<NMyClass::ACTRLFLAGS>();
    

    but even if I don't see anymore an error regarding the connection at run-time, it simply doesn't work... my slot is not called at all...

    any ideas ?

    thanks in advance

    Giampaolo

    [Added code tags ~kshegunov]

    kshegunovK 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      IIRC, you need to also provide the QDataStream operators for your flags and register them with qRegisterMetaTypeStreamOperators so they can be serialised in QVariant.

      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
      • I Offline
        I Offline
        iw2lsi
        wrote on last edited by
        #3

        Hello SGaist...

        just for a test, I've replaced my QFlags with a plain int... and it doesn't work.... so the problem must be elsewhere...

        I'll try again tomorrow :D :D :D

        Best Regards
        
                   Giampaolo
        
        jsulmJ A 2 Replies Last reply
        0
        • I iw2lsi

          Hello SGaist...

          just for a test, I've replaced my QFlags with a plain int... and it doesn't work.... so the problem must be elsewhere...

          I'll try again tomorrow :D :D :D

          Best Regards
          
                     Giampaolo
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @iw2lsi Does it work in the same thread?

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

          1 Reply Last reply
          0
          • I iw2lsi

            Hello SGaist...

            just for a test, I've replaced my QFlags with a plain int... and it doesn't work.... so the problem must be elsewhere...

            I'll try again tomorrow :D :D :D

            Best Regards
            
                       Giampaolo
            
            A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            @iw2lsi Show us the code for the signal, slot, and where you connect one to the other.

            And if possible the code for the thread start and creation.

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            1
            • I iw2lsi

              Dear all,

              using Qt4.8.7, I'm in trouble trying to connect a signal to a slot on a different thread when signal/slot argument contains a QFlags...

              first of all... is this possible at all ?

              I'm declaring my flags as usual, with

                 Q_DECLARE_FLAGS (ACTRLFLAGS, ACTRLFLAG) 
              

              and

                  Q_DECLARE_OPERATORS_FOR_FLAGS( NMyClass::ACTRLFLAGS )
              

              but this seems not enougth when the connection is (queued) between threads... then I've try registering the type with

                 Q_DECLARE_METATYPE(NMyClass::ACTRLFLAGS)
              

              and

                qRegisterMetaType<NMyClass::ACTRLFLAGS>();
              

              but even if I don't see anymore an error regarding the connection at run-time, it simply doesn't work... my slot is not called at all...

              any ideas ?

              thanks in advance

              Giampaolo

              [Added code tags ~kshegunov]

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @iw2lsi said in Passing QFlags between threads:

              qRegisterMetaType<NMyClass::ACTRLFLAGS>();
              

              but even if I don't see anymore an error regarding the connection at run-time, it simply doesn't work... my slot is not called at all...

              Depending on how you do the signal-slot connection and/or slot call you may need to adjust this line. Please show us the code for that as @ambershark mentioned.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • I Offline
                I Offline
                iw2lsi
                wrote on last edited by
                #7

                Hi all,

                first of all, thanks for the support and sorry for the delay...

                The problem was in my receiver thread... basically my consumer process was blocking the event loop in a waitcondition, and that's why I was not receiving the signals... Nothing was wrong in the way my QFlags was registered on the meta-object system...

                 thanks again,
                
                          Giampaolo
                
                1 Reply Last reply
                1

                • Login

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