Results 1 to 5 of 5

Thread: [GUI Thread]: Choosing it ! How to ?

  1. #1
    Join Date
    Sep 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question [GUI Thread]: Choosing it ! How to ?

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: [GUI Thread]: Choosing it ! How to ?

    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.

  3. #3
    Join Date
    Sep 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [GUI Thread]: Choosing it ! How to ?

    Quote Originally Posted by tbscope View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: [GUI Thread]: Choosing it ! How to ?

    Quote Originally Posted by didier View Post
    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.

  5. #5
    Join Date
    Sep 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [GUI Thread]: Choosing it ! How to ?

    A plug-in based system should be the solution. Fine.
    I'm going to study that.
    Thanks a lot.

Similar Threads

  1. Replies: 9
    Last Post: 28th November 2009, 20:31
  2. Replies: 16
    Last Post: 7th October 2009, 08:17
  3. IDE to choose
    By sepehr in forum Qt Programming
    Replies: 8
    Last Post: 11th September 2008, 18:31
  4. Main thread - worker thread communication.
    By kikapu in forum Newbie
    Replies: 25
    Last Post: 23rd May 2007, 22:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.