Results 1 to 8 of 8

Thread: Refresh the mainwindow / functions called in the main loop

  1. #1

    Default Refresh the mainwindow / functions called in the main loop

    Hi guys,

    I have this situation:

    I have a QMainWindow that contains a QToolBar and a QMenuBar.

    I need to disable them, do some computation and enable them again after that.

    The problem is that the code:

    Qt Code:
    1. menuBar()->setDisable(true);
    2. myToolBar_->setDisable(true);
    3.  
    4. // do a lot of computation
    5.  
    6. menuBar()->setDisable(false);
    7. myToolBar_->setDisable(false);
    To copy to clipboard, switch view to plain text mode 

    doesn't work. I guess the QMainWindow has a loop and the operations to refresh everything are called only at the end of this loop.
    It should work if the mainwindow internal loop is accessed two times or if I call a function to force the update.

    I have tried to call both update(), refresh() and show() (both of the mainWindow and of the other widgets) but I didn't succeed.

    Do you know anything I can do about that?

    I have also tried to use signals and slots but even in this way it didn't work...


    Cheers

  2. #2
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Refresh the mainwindow / functions called in the main loop

    May be this could help, if you call this method before doing computation, it should refresh you GUI.
    http://doc.qt.io/qt-4.8/qcoreapplication.html#processEvents

  3. #3
    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: Refresh the mainwindow / functions called in the main loop

    Be advised that blocking the event processing of the UI thread is usually not a very good idea, since you program will stop responding to any kinds of events.
    No user interaction, no redrawing, no timers, no sockets, etc.

    Cheers,
    _

  4. #4

    Default Re: Refresh the mainwindow / functions called in the main loop

    Quote Originally Posted by nix View Post
    May be this could help, if you call this method before doing computation, it should refresh you GUI.
    http://doc.qt.io/qt-4.8/qcoreapplication.html#processEvents
    Uhm ok, thank you. It's a method of the QCoreApplication so I assume I should pass a reference to it in my mainwindow, right?

    Quote Originally Posted by anda_skoa View Post
    Be advised that blocking the event processing of the UI thread is usually not a very good idea, since you program will stop responding to any kinds of events.
    No user interaction, no redrawing, no timers, no sockets, etc.

    Cheers,
    _
    I appreciate your suggestions and yes, maybe it would be better to process all this data in a thread but I don't need the GUI when doing the computation (they just load stuff).

    For all the real computation I am using threads indeed.


    Thank you again
    Last edited by valerianst; 1st October 2013 at 16:33.

  5. #5
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Refresh the mainwindow / functions called in the main loop

    Uhm ok, thank you. It's a method of the QCoreApplication so I assume I should pass a reference to it in my mainwindow, right?
    No, it's a static method, just do QCoreApplication:rocessEvents();

  6. #6

    Default Re: Refresh the mainwindow / functions called in the main loop

    Quote Originally Posted by nix View Post
    No, it's a static method, just do QCoreApplication:rocessEvents();
    Just tried.

    No difference at all.. Don't know why


    Added after 40 minutes:


    Just notice that if I do:

    Qt Code:
    1. this ->update();
    2. this ->repaint();
    3. QCoreApplication::processEvents();
    To copy to clipboard, switch view to plain text mode 


    The toolbar greys out but not the menubar
    Last edited by valerianst; 2nd October 2013 at 11:55.

  7. #7
    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: Refresh the mainwindow / functions called in the main loop

    Since you don't need your UI at all, have you tried
    Qt Code:
    1. this->setEnabled(false);
    To copy to clipboard, switch view to plain text mode 
    i.e. disabling the whole window?

    Or instead of disabling, showing a modal progress dialog?

    Cheers,
    _

  8. #8

    Default Re: Refresh the mainwindow / functions called in the main loop

    Quote Originally Posted by anda_skoa View Post
    Since you don't need your UI at all, have you tried
    Qt Code:
    1. this->setEnabled(false);
    To copy to clipboard, switch view to plain text mode 
    i.e. disabling the whole window?

    Or instead of disabling, showing a modal progress dialog?

    Cheers,
    _
    Yep, I have tried both.

    Disabling the whole window doesn't change anything.

    Showing a modal dialog should be fine but I'd prefer a different solution.

Similar Threads

  1. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 16:31
  2. Replies: 4
    Last Post: 19th August 2009, 19:38
  3. main loop
    By dusza in forum Qt Programming
    Replies: 10
    Last Post: 6th June 2009, 17:29
  4. Refresh the Mainwindow at run time
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 15th November 2007, 13:16
  5. mainwindow does not refresh
    By edb in forum Qt Programming
    Replies: 22
    Last Post: 25th January 2006, 16:42

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.