As Flavius Suciu has mentioned, you can use a cross-thread signal/slot connection. They can also carry arguments, however, if you don't pass just fundamental types or Qt types as signal parameters but, say, your own custom struct
, you need to tell Qt about them this way:
namespace MyNamespace { // if any...
struct MyClass { /* ... */ };
} // if any
Q_DECLARE_METATYPE( MyNamespace::MyClass )
This allows MyClass
to be stuffed into QVariant
s, which is what Qt uses internally to ship copies of the signal arguments over thread boundaries.
You might also need to call
qRegisterMetatype<MyNamespace::MyClass>( "MyNamespace::MyClass" );
somewhere it's bound to be executed before any signal/slot cross-thread connection is attempted (e.g. in main()
, or your QThread
subclass constructor).
See the docs of Q_DECLARE_METATYPE