Cant call QObject::thread() / this->thread()
-
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();
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
-
@Dariusz said in Cant call QObject::thread() / this->thread():
I keep on getting errors
What errors?
-
@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
-
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."
-
@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!
-
@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.