I've a menu screen which must be updated before the login screen closed. The code is something similar to below one;
emit updateMainMenuAccordingToUserRights;
QCoreApplication::processEvents();
emit jumpMainMenu();
The problem is 'how can I be sure that all events have been processed?'. Because some of the slots triggered by updateMainMenuAccordingToUserRights signal adds new events to the event loop to update view components. Before jumping main menu I must be sure that it's already updated. I've searched a little and seen that QCoreApplication::processEvent process the loop for just once. Okay, that's the reason why the above code does not work. Even I tried some QEventLoop methods but couldn't manage to solve this problem.
Thanks for any advice.
Not at all - it's an XY problem. In other words: your design is wrong. You need to lightly couple the login screen somehow to the menu screen, so that the menu screen gets the information it needs to update itself, before the login screen is closed. At any point after that, the login screen can indeed close.
Most likely you're tightly coupling the login screen with login controller, and thus the
LoginScreenclass should emit the event that theMenuScreenwill process.Your current signal names suggest very tight coupling between the screens. There is just one signal that you need:
loginDone(const LoginData &), whereLoginDatais a structure/class that carries the information about the logged in user etc.Then, the three lines of code from the question simply become:
and
A function (ideally in a controller class) would then couple the
LoginScreentoMenuScreenloosely via theLoginDataobject:Ideally, you'd want to have a separate controller class to implement the logic, instead of having it in screens. The
LoginScreenandMenuScreencould then be views for the data exposed by the controller.