Results 1 to 4 of 4

Thread: Updating GUI while processing

  1. #1
    Join Date
    Apr 2015
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Updating GUI while processing

    I want to update widgets while my program is working, so the user can see the progress. For example, I would like to update the text in a column in a QTreeWidget when certain steps are completed, like "Conntecting to host...", "Logging in..." etc. Using QTreeWidget.setText() here and there does not work, I only see the last text when the whole process is completed. A couple of questions on this:

    - Are multiple threads required for this?
    - Do you have to call QTreeWidget.setText() from the main loop?

    Any tips on where to read up on this is appriciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Updating GUI while processing

    Quote Originally Posted by ecce View Post
    - Are multiple threads required for this?
    Not necessarily.
    If the work can be done in steps, then each step could return to the event loop and the next step would be scheduled, e.g. using a single shot timer.
    Or you all QCoreApplication:rocessEvents()

    But a thread might still be nice if the processing should really happen in parallel.

    Quote Originally Posted by ecce View Post
    - Do you have to call QTreeWidget.setText() from the main loop?
    Yes, widget methods always need to be called by the main thread.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2015
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Updating GUI while processing

    This is a stupid question and I've avoided id for a time but... where is the main loop? This is how I start my application:

    Qt Code:
    1. if __name__ == '__main__':
    2. try:
    3. myApp = QtGui.QApplication(sys.argv)
    4. mainWindow = MainWindow()
    5. myApp.exec_()
    6.  
    7. ....
    8.  
    9.  
    10. class MainWindow(QtGui.QMainWindow):
    11.  
    12. def __init__(self):
    13. QtGui.QMainWindow.__init__(self)
    14. self.setWindowTitle("Test Application")
    15. self.setGeometry(0, 0, 1000, 900)
    16. self.CreateStatusBar()
    17. self.show()
    18.  
    19. ....
    To copy to clipboard, switch view to plain text mode 

    So if I want to put code in the main loop, where do I put it?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Updating GUI while processing

    You don't put your code "in" the main loop. The loop is implemented inside the application's exec() call. It waits for events and processes them. Such event can be a timer timing out or a queued slot invocation. The point is to not create a while loop (or similar) in your code as this prevents events (such as redrawing widgets) to be executed.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. image processing
    By IRON_MAN in forum Qt Programming
    Replies: 4
    Last Post: 18th November 2009, 13:37
  2. Event Processing
    By QbelcorT in forum Qt for Embedded and Mobile
    Replies: 10
    Last Post: 15th April 2009, 23:48
  3. Image processing
    By NicNac in forum Newbie
    Replies: 25
    Last Post: 2nd November 2008, 10:05
  4. Image Processing using Qt
    By danielperaza in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2008, 18:15
  5. XML processing instruction
    By mattia in forum Newbie
    Replies: 1
    Last Post: 26th February 2008, 11:37

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.