Results 1 to 2 of 2

Thread: Dialog in a QThread

  1. #1
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Dialog in a QThread

    I have been trying to get a spawned thread to create a dialog! Everytime I run the code it asserts saying it can not create a widget in a non GUI thread.

    Is there any way to do this?

    Pretty much I just have a class that inherits from QThread. In run() I am wanting to initialize and show a dialog.

    If you are wondering WHY am I doing this... I want to call a method in this class to open the dialog (which will be doing a lot of stuff) and then start a search. When the search is over it will call another method from the class to stop the thread, essentially closing the dialog.

    So pretty much I am wanting to create a splash screen that I can turn on and off at will.

  2. #2
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Dialog in a QThread

    There are issues on some of the platforms that currently limit Qt to only one GUI thread. This is being worked on, and the Trolls expect that this limitation will be gone in Qt5. In the meantime, however, all GUI operations need to be performed in the main GUI thread. That means no widgets, dialogs, painting, and a few not-so-obvious things like no QPixmaps either.

    There is an easy workaround, however. In Qt4 you can send signals to objects owned by another thread. This is sent asynchronously. So you can create a dialog in the main GUI thread, show it in response to a signal sent when the worker thread starts, and hide it in response to a signal sent when the worker thread finishes. If you're using Qt3, you can create a similar solution by using your favorite inter-thread communication mechanism.

    The Qt4 mandelbrot demo has an example of inter-thread signals and slots.

Similar Threads

  1. [itemview] delegation to a dialog ...
    By lauranger in forum Qt Programming
    Replies: 6
    Last Post: 27th November 2006, 10:08
  2. Replies: 3
    Last Post: 23rd July 2006, 18:02
  3. Show/hide part of dialog with resizing.
    By Spockmeat in forum Qt Tools
    Replies: 6
    Last Post: 7th June 2006, 08:22
  4. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 22:51
  5. Dialog positioning in GNOME
    By simk in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2006, 09:41

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.