2

I'm very interested in reusing metaobject system and general functionality, but don't know exactly:

  • Has QMetaObject::invokeMethod() dependency on event loop?
  • Can I load plugins without QCoreApplication instance?
  • ...

Some list of using restrictions of this module in non-qt application/in non-main thread would be greatly appreciated.

UPDATE:

I have posted same question to Qt community.

Iakov Minochkin
  • 432
  • 2
  • 10

1 Answers1

0

A running event loop is optional and is per-thread. If you don't process events in a given thread, it doesn't need one.

invokeMethod has no dependencies on the event loop if you invoke methods on objects that live in the thread where you call this method. If you invoke methods on objects that live in other threads, said threads will need to run the event loop, even if only periodically. They can, after all, call processEvents at well-defined points. A cross-thread slot invocation is equivalent to posting an event to the thread's event queue.

I will check if the plugin mechanism works without a QCoreApplication instance, but this instance doesn't hurt you any. Just create it and forget it. You don't need to run the event loop in the main thread, or in any thread for that matter.

Do note that QPluginLoader is not the same as QLibrary, you need to examine your needs and figure out which you want.

A non-gui QCoreApplication can be created in an arbitrary thread, and its event loop can run there. On Windows, a QApplication can be created in an arbitrary thread as well.

Community
  • 1
  • 1
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313