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. Cant call QObject::thread() / this->thread()

Cant call QObject::thread() / this->thread()

Scheduled Pinned Locked Moved Unsolved General and Desktop
qthread
9 Posts 4 Posters 1.0k 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 18 May 2021, 07:34 last edited by
    #1

    Hey
    I'm loosing my mind :- )

    I've no idea how to reproduce it as the code was working just fine yesterday... ehh happy morning. Anyway

    I have
    ThreadA creates object_X
    ThreadB created object_K
    ThreadC sets = object_K->setParent(object_X) using > QMetaObject::invokeMethod(object_K,[&](){object_K->setParent(this);},Qt::QueuedConnection);
    ThreadC sets = QMetaObject::invokeMethod(object_X,[&,threadPointer=threadC](){this->moveToThread(threadPointer);},Qt::QueuedConnection);

    I keep on getting errors when ever I call thread()/object_X->thread();
    6205366d-553a-407a-8b94-fcdc3e0b8ed8-image.png
    8355c21d-4157-4382-8cf8-95bac8dc273f-image.png

    I literally was doing that yesterday and I had 0 issues, now everything goes bananas after making a new worker thread to finish initializations. Yesterday I was doing all in ThreadB, now I decided to do it in threadC to help concurrency.

    He literally crashes before I even start moving objects to different threads... but just asking whats object thread. sigh!

    Qt 6.0.2 gonna see if there is new one I can update to :x

    J V 2 Replies Last reply 18 May 2021, 07:37
    0
    • D Dariusz
      18 May 2021, 07:34

      Hey
      I'm loosing my mind :- )

      I've no idea how to reproduce it as the code was working just fine yesterday... ehh happy morning. Anyway

      I have
      ThreadA creates object_X
      ThreadB created object_K
      ThreadC sets = object_K->setParent(object_X) using > QMetaObject::invokeMethod(object_K,[&](){object_K->setParent(this);},Qt::QueuedConnection);
      ThreadC sets = QMetaObject::invokeMethod(object_X,[&,threadPointer=threadC](){this->moveToThread(threadPointer);},Qt::QueuedConnection);

      I keep on getting errors when ever I call thread()/object_X->thread();
      6205366d-553a-407a-8b94-fcdc3e0b8ed8-image.png
      8355c21d-4157-4382-8cf8-95bac8dc273f-image.png

      I literally was doing that yesterday and I had 0 issues, now everything goes bananas after making a new worker thread to finish initializations. Yesterday I was doing all in ThreadB, now I decided to do it in threadC to help concurrency.

      He literally crashes before I even start moving objects to different threads... but just asking whats object thread. sigh!

      Qt 6.0.2 gonna see if there is new one I can update to :x

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 18 May 2021, 07:37 last edited by
      #2

      @Dariusz said in Cant call QObject::thread() / this->thread():

      I keep on getting errors

      What errors?

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

      D 2 Replies Last reply 18 May 2021, 07:53
      1
      • J jsulm
        18 May 2021, 07:37

        @Dariusz said in Cant call QObject::thread() / this->thread():

        I keep on getting errors

        What errors?

        D Offline
        D Offline
        Dariusz
        wrote on 18 May 2021, 07:53 last edited by
        #3

        @jsulm Need a min... I just installed 6.1.0 and I got >

        CMake Error at C:/Qt/6.1.0/msvc2019_64/lib/cmake/Qt6/QtFeature.cmake:1017 (message):
          Feature poll_select is already defined and has a different value when
          importing features from Qt6::Core.
        

        Today is special T_T

        A 1 Reply Last reply 5 Jun 2021, 18:20
        0
        • J jsulm
          18 May 2021, 07:37

          @Dariusz said in Cant call QObject::thread() / this->thread():

          I keep on getting errors

          What errors?

          D Offline
          D Offline
          Dariusz
          wrote on 18 May 2021, 09:02 last edited by
          #4

          @jsulm Well that was a fun hour... anywy... error >
          c26eda61-cd44-4377-9a8a-9176fa1e20cd-image.png

          1 Reply Last reply
          0
          • D Dariusz
            18 May 2021, 07:34

            Hey
            I'm loosing my mind :- )

            I've no idea how to reproduce it as the code was working just fine yesterday... ehh happy morning. Anyway

            I have
            ThreadA creates object_X
            ThreadB created object_K
            ThreadC sets = object_K->setParent(object_X) using > QMetaObject::invokeMethod(object_K,[&](){object_K->setParent(this);},Qt::QueuedConnection);
            ThreadC sets = QMetaObject::invokeMethod(object_X,[&,threadPointer=threadC](){this->moveToThread(threadPointer);},Qt::QueuedConnection);

            I keep on getting errors when ever I call thread()/object_X->thread();
            6205366d-553a-407a-8b94-fcdc3e0b8ed8-image.png
            8355c21d-4157-4382-8cf8-95bac8dc273f-image.png

            I literally was doing that yesterday and I had 0 issues, now everything goes bananas after making a new worker thread to finish initializations. Yesterday I was doing all in ThreadB, now I decided to do it in threadC to help concurrency.

            He literally crashes before I even start moving objects to different threads... but just asking whats object thread. sigh!

            Qt 6.0.2 gonna see if there is new one I can update to :x

            V Offline
            V Offline
            VRonin
            wrote on 18 May 2021, 09:22 last edited by
            #5

            object_K->setParent(this);

            this->moveToThread

            What is this in these 2 calls?

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            D 1 Reply Last reply 18 May 2021, 09:31
            1
            • V VRonin
              18 May 2021, 09:22

              object_K->setParent(this);

              this->moveToThread

              What is this in these 2 calls?

              D Offline
              D Offline
              Dariusz
              wrote on 18 May 2021, 09:31 last edited by
              #6

              @VRonin My bad its object_X.
              I essentially send invokeFunction to the object to tell him to change his thread/parent to a different one. I take changing of thread has to happen on the object thread and not destination thread?

              TIA

              1 Reply Last reply
              0
              • V Offline
                V Offline
                VRonin
                wrote on 18 May 2021, 09:35 last edited by VRonin
                #7

                My bad its object_X.

                Are you sure? In both cases?


                I take changing of thread has to happen on the object thread and not destination thread?

                Indeed, from https://doc.qt.io/qt-5/qobject.html#moveToThread

                Warning: This function is not thread-safe; the current thread must be same as the current thread affinity. In other words, this function can only "push" an object from the current thread to another thread, it cannot "pull" an object from any arbitrary thread to the current thread. There is one exception to this rule however: objects with no thread affinity can be "pulled" to the current thread."

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                D 1 Reply Last reply 18 May 2021, 11:23
                3
                • V VRonin
                  18 May 2021, 09:35

                  My bad its object_X.

                  Are you sure? In both cases?


                  I take changing of thread has to happen on the object thread and not destination thread?

                  Indeed, from https://doc.qt.io/qt-5/qobject.html#moveToThread

                  Warning: This function is not thread-safe; the current thread must be same as the current thread affinity. In other words, this function can only "push" an object from the current thread to another thread, it cannot "pull" an object from any arbitrary thread to the current thread. There is one exception to this rule however: objects with no thread affinity can be "pulled" to the current thread."

                  D Offline
                  D Offline
                  Dariusz
                  wrote on 18 May 2021, 11:23 last edited by
                  #8

                  @VRonin I think with so many thread switching I managed to 100% hit some kind of thread mutex/error. I'm now remaking the logic to create objects in correct threads from the beginning rather than moving them there... fingers cross this put an end to it. The amount of banana errors I'm getting is getting outa hand!

                  1 Reply Last reply
                  2
                  • D Dariusz
                    18 May 2021, 07:53

                    @jsulm Need a min... I just installed 6.1.0 and I got >

                    CMake Error at C:/Qt/6.1.0/msvc2019_64/lib/cmake/Qt6/QtFeature.cmake:1017 (message):
                      Feature poll_select is already defined and has a different value when
                      importing features from Qt6::Core.
                    

                    Today is special T_T

                    A Offline
                    A Offline
                    abhishekm
                    wrote on 5 Jun 2021, 18:20 last edited by
                    #9

                    @Dariusz Can you help with the solution that you did to solve the cmake error that you were getting :
                    CMake Error at C:/Qt/6.1.0/msvc2019_64/lib/cmake/Qt6/QtFeature.cmake:1017 (message):
                    Feature poll_select is already defined and has a different value when
                    importing features from Qt6::Core.

                    I am getting the same error when I moved to Qt 6.1. Using the static libs of Qt, built from source.

                    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