Results 1 to 2 of 2

Thread: Changing MainWindow UI from another QThread.

  1. #1
    Join Date
    Aug 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Changing MainWindow UI from another QThread.

    Hello, I was writing my application and at some point I came in need to increment progress bar from another thread and do some UI changes. I have tried these:
    1. Passing UI to thread, and changing it directly, but program came in much errors (QCoreApplication ASSERT failure if I remember correctly).
    2. Emitting signals to MainWindow. Seems to work correctly, but only when qt::queuedconnection was set. If I set it to direct connection program throws the same ASSERT failure in debug mode. I am not satisfied with queued connection, because I want to increment progressbar`s value immediately, not when thread finishes.
    How could I do this? Thanks in advance.

  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: Changing MainWindow UI from another QThread.

    Quote Originally Posted by EdgeLuxe View Post
    Hello, I was writing my application and at some point I came in need to increment progress bar from another thread and do some UI changes. I have tried these:
    1. Passing UI to thread, and changing it directly, but program came in much errors (QCoreApplication ASSERT failure if I remember correctly).
    Please read the documentation. It's stated on multiple pages that ALL of the user interface needs to be in the main thread.
    You can NOT do user interface related things in a separate thread.

    This does NOT mean you can't make your program multithreaded though.

    2. Emitting signals to MainWindow. Seems to work correctly, but only when qt::queuedconnection was set. If I set it to direct connection program throws the same ASSERT failure in debug mode. I am not satisfied with queued connection, because I want to increment progressbar`s value immediately, not when thread finishes.
    Connections across threads NEED to be queued. Signals and slots are handled in the event loop of the object. If an object lives in a different thread, it has a different event loop and you need to wait till the receiving object is in its own event loop. Therefor you need a queued connection.

    It's not true that you need to wait for a thread to finish before you can send something.
    But if this is all a little bit too difficult, I suggest you take a look at QtConcurrent and use a Future watcher.

Similar Threads

  1. Replies: 2
    Last Post: 10th August 2009, 09:45
  2. Control MainWindow from QThread
    By lixo1 in forum Qt Programming
    Replies: 4
    Last Post: 16th February 2009, 10:33
  3. Replies: 4
    Last Post: 26th June 2008, 18:41
  4. Spawn a QThread in another QThread
    By david.corinex in forum Qt Programming
    Replies: 2
    Last Post: 19th December 2007, 12:54
  5. Replies: 6
    Last Post: 17th March 2006, 17:48

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.