PDA

View Full Version : Refresh the mainwindow / functions called in the main loop



valerianst
1st October 2013, 16:38
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:




menuBar()->setDisable(true);
myToolBar_->setDisable(true);

// do a lot of computation

menuBar()->setDisable(false);
myToolBar_->setDisable(false);



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

nix
1st October 2013, 17:01
May be this could help, if you call this method before doing computation, it should refresh you GUI.
qcoreapplication.html#processEvents

anda_skoa
1st October 2013, 17:10
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,
_

valerianst
1st October 2013, 17:26
May be this could help, if you call this method before doing computation, it should refresh you GUI.
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?


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

nix
2nd October 2013, 08:17
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::processEvents();

valerianst
2nd October 2013, 12:55
No, it's a static method, just do QCoreApplication::processEvents();

Just tried.

No difference at all.. Don't know why

Added after 40 minutes:

Just notice that if I do:



this ->update();
this ->repaint();
QCoreApplication::processEvents();



The toolbar greys out but not the menubar

anda_skoa
2nd October 2013, 14:40
Since you don't need your UI at all, have you tried


this->setEnabled(false);

i.e. disabling the whole window?

Or instead of disabling, showing a modal progress dialog?

Cheers,
_

valerianst
2nd October 2013, 15:57
Since you don't need your UI at all, have you tried


this->setEnabled(false);

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.