PDA

View Full Version : [GUI Thread]: Choosing it ! How to ?



didier
13th October 2010, 22:54
I'm currently developping a plug-in for a non Qt application.

This plug-in is a server with HMI all developped with Qt.

I guess the best to do is to create all the Qt objects in a same thread and take profit of signals and slots.

The plug-in is called by the application through its interface:
void init();
void run();
void term();

The server must be created in init().
run() is triggered by the user and show the HMI (a control panel of the server)

But the thread that creates all my Qt objects is not the GUI Thread. The main thread is the one that execute init() and makes running the host application. So, I can't end init() by calling QApplication::exec(). It's why a secondary thread is used to play the role of deamon, creator of all the Qt objects.

As this thread is not the GUI thread, I must elect it as the GUI thread.

How is it possible to do that ?

A post speaks about that but does'nt detail how to do. It seems to be related to the thread which loads the QtGui lib (or, maybe, initializes the global variables of this lib).

Thanks a lot if you can help me.

tbscope
14th October 2010, 05:35
You can't create widgets in anything other than the main thread of the application (the GUI thread).

However, you can pass an ui file (xml file describing the user interface) from another thread to the main thread and let the main thread construct the user interface based on that ui file.

didier
15th October 2010, 00:43
However, you can pass an ui file (xml file describing the user interface) from another thread to the main thread and let the main thread construct the user interface based on that ui file.

It's just what I must to avoid.

I'm searching how to build an executable with deferred linking of the QtGui.
It should be good to solve my trouble.

tbscope
15th October 2010, 06:22
It's just what I must to avoid.

I'm searching how to build an executable with deferred linking of the QtGui.
It should be good to solve my trouble.

You can NOT create widgets from other threads.

Just tell the main thread what it needs to create, and the most simple method to do that is send a .ui xml file to the main thread and create a new widget from the main thread. Everything to do that is already there.

Or, create a plugin base system containing a gui part and the daemon thread. That way you can keep everything together and you don't need to set up everything in the main program.

didier
15th October 2010, 10:03
A plug-in based system should be the solution. Fine.
I'm going to study that.
Thanks a lot.