QObject's QThread from shared library
-
Hello everyone! Questions about classes inherited from QObject in shared library and it's usage in the main application. Currently on Qt 6.5.0.
I have a shared library with test class like this:
class LIB_EXPORT Tester: public QObject { Q_OBJECT public: Tester(QObject* parent = nullptr):QObject(parent){}; ~Tester() = default; };In main application I link the library and use it:
Tester test; qDebug() << QThread::currentThread(); qDebug() << test.thread();And output is like this:
QThread(0x2b484981b50) QThread(0x2b4849c3990)So I cannot correctly work with this class, e.g. cannot move it to desired thread and so on. Even if in my main application I create derived class from Tester, it will be created in another thread.
Is it correct behaviour? If so, what is the correct way to work with? -
This is working fine for me
int main(int argc, char* argv[]) { QApplication app(argc, argv); QObject obj; qDebug() << QThread::currentThread(); qDebug() << obj.thread(); return 0; }-->
QThread(0x26c3915b030, name = "Qt mainThread")
QThread(0x26c3915b030, name = "Qt mainThread")You must be doing something in your Tester ctor.
-
This is working fine for me
int main(int argc, char* argv[]) { QApplication app(argc, argv); QObject obj; qDebug() << QThread::currentThread(); qDebug() << obj.thread(); return 0; }-->
QThread(0x26c3915b030, name = "Qt mainThread")
QThread(0x26c3915b030, name = "Qt mainThread")You must be doing something in your Tester ctor.
@Christian-Ehrlicher said in QObject's QThread from shared library:
You must be doing something in your Tester ctor.
In the code above you can see that there is totally empty ctor :)
But looks like that I have found the issue. Need to check it tomorrow. -
Still doesn't know, if this is a correct behaviour (can be logically explained, I mean), but the issue was quite simple. Somehow library's versions were mixed and debug shared library was linked to app's release version and vice versa. In this case QObjects from library (including inherited classes' objects) are created in a different QThread.