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. how do i UpdateUI in a Callback which is non-mainThread & non-QtThread?

how do i UpdateUI in a Callback which is non-mainThread & non-QtThread?

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 5 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.
  • O Offline
    O Offline
    opengpu
    wrote on last edited by
    #1

    how do i UpdateUI in a Callback which is non-mainThread & non-QtThread?
    the data is updating in that thread which is not mainThread or QtThread...so i cannot emit signal in that Callback func

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      May or may not be a more direct way to handle it but create a function under a QObject class that looks for some non-Qt syncronization signal (POSIX methods: signal, semaphore state chagne, etc) and when it receives the appropriate event, emit the Qt signal necessary to do your update.

      1 Reply Last reply
      2
      • O Offline
        O Offline
        opengpu
        wrote on last edited by
        #3

        all i have in exe code it that callback func.
        and i plan to create inhrite a class from QObject.
        and let it MyObject* g_pMy; it global.
        and then in that callback fun, just use g_pMy->emit

        is this method ok?

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

          Hi,

          What parameters can you pass to that callback ?

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

          O 1 Reply Last reply
          2
          • SGaistS SGaist

            Hi,

            What parameters can you pass to that callback ?

            O Offline
            O Offline
            opengpu
            wrote on last edited by
            #5

            @SGaist nothing, the callback is returnedn by a DLL from 3rdParty

            aha_1980A 1 Reply Last reply
            0
            • O opengpu

              @SGaist nothing, the callback is returnedn by a DLL from 3rdParty

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @opengpu can you please provide a bit more information? how does the callbacks function signature look like?

              Qt has to stay free or it will die.

              O 1 Reply Last reply
              1
              • aha_1980A aha_1980

                @opengpu can you please provide a bit more information? how does the callbacks function signature look like?

                O Offline
                O Offline
                opengpu
                wrote on last edited by
                #7

                @aha_1980 just a callback funtion in windows dev, but that callback is returned from a 3rdParty DLL which use COM

                aha_1980A 1 Reply Last reply
                0
                • O opengpu

                  @aha_1980 just a callback funtion in windows dev, but that callback is returned from a 3rdParty DLL which use COM

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @opengpu

                  you didn't answer my question.

                  how does the callbacks function signature look like?

                  Qt has to stay free or it will die.

                  O 1 Reply Last reply
                  1
                  • aha_1980A aha_1980

                    @opengpu

                    you didn't answer my question.

                    how does the callbacks function signature look like?

                    O Offline
                    O Offline
                    opengpu
                    wrote on last edited by
                    #9

                    @aha_1980
                    WINAPI Callback(const Data& data)
                    {
                    //here is not mainThread; so i have to pass the data by value to the slot which is in mainThread; or i use mutex & save data to m_data, and then in slot mainThread getData also with mutex protect thread-safety
                    }

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      opengpu
                      wrote on last edited by opengpu
                      #10

                      is this a good way to emit signal in the non-thread non-qt Callback function?

                      WINAPI Callback(const Data& data)
                      {//here is not mainThread; so i have to pass the data by value to the slot which is in mainThread; or i use mutex & save data to m_data, and then in slot mainThread getData also with mutex protect thread-safety
                          emit g_qtObj->mySignal();
                      }
                      
                      class QtObj : public QObject
                      {
                      Q_OBJECT
                      signals:
                          void mySignal();
                      }
                      QtObj g_obj;
                      QtObj* g_qtObj = &g_obj;
                      
                      jsulmJ 1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Use QMetaObject::invokeMethod

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

                        O 1 Reply Last reply
                        2
                        • O opengpu

                          is this a good way to emit signal in the non-thread non-qt Callback function?

                          WINAPI Callback(const Data& data)
                          {//here is not mainThread; so i have to pass the data by value to the slot which is in mainThread; or i use mutex & save data to m_data, and then in slot mainThread getData also with mutex protect thread-safety
                              emit g_qtObj->mySignal();
                          }
                          
                          class QtObj : public QObject
                          {
                          Q_OBJECT
                          signals:
                              void mySignal();
                          }
                          QtObj g_obj;
                          QtObj* g_qtObj = &g_obj;
                          
                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @opengpu said in how do i UpdateUI in a Callback which is non-mainThread & non-QtThread?:

                          g_qtObj->emit mySignal();

                          should be

                          g_qtObj->mySignal();
                          

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

                          O 1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @opengpu said in how do i UpdateUI in a Callback which is non-mainThread & non-QtThread?:

                            g_qtObj->emit mySignal();

                            should be

                            g_qtObj->mySignal();
                            
                            O Offline
                            O Offline
                            opengpu
                            wrote on last edited by
                            #13

                            @jsulm thanks

                            1 Reply Last reply
                            0
                            • SGaistS SGaist

                              Use QMetaObject::invokeMethod

                              O Offline
                              O Offline
                              opengpu
                              wrote on last edited by
                              #14

                              @SGaist ```
                              WINAPI Callback(const Data& data)
                              {//here is not mainThread; so i have to pass the data by value to the slot which is in mainThread; or i use mutex & save data to m_data, and then in slot mainThread getData also with mutex protect thread-safety
                              //emit g_qtObj->mySignal();
                              QMetaObject::invokeMethod(g_pQtMainWindow, slotDoSth, Qt::QueuedConnection);
                              }

                              like this? use invokeMethod instead of emit signal ?
                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                Why do you have a global Qt object ?
                                What makes you define your Callback method like that ?

                                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
                                • O Offline
                                  O Offline
                                  opengpu
                                  wrote on last edited by
                                  #16

                                  why QMetaObject::invokeMethod pass custom-type called Twice custom-type's copy constructor...
                                  https://forum.qt.io/topic/102915/qmetaobject-invokemethod-pass-custom-type-called-twice-custom-type-s-copy-constructor

                                  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