Qt 6.11 is out! See what's new in the release
blog
How to make the main thread wait for a certain action is performed in the UI
General and Desktop
6
Posts
4
Posters
5.6k
Views
1
Watching
-
Maybe "QMutex":http://doc.qt.nokia.com/4.7/qmutex.html#details ?
-
My bad.
It's like My program has 3 UI Windows: Welcome.ui, Server.ui and Client.ui.
User can specify her identity as one of the two roles in the welcome window.
Base on the role chosen, the main function run the corresponding children thread which keeps listening for messages.My main function is like:
@int main(int argc, char *argv[])
{
QApplication a(argc, argv);
EC w;
w.show();AdminWindow aw; UserWindow uw; QObject::connect(&w, SIGNAL(server_go()), &aw, SLOT(on_server_go())); QObject::connect(&w, SIGNAL(user_go()),&uw,SLOT(on_user_go()));while(!aw.if_show&&!uw.if_show){
sleep(1) ; //try to use sleep to make the main function wait, but fails. the main function is kinda of blocked here
}if(aw.if_show){ //this is a sever cout<<"starts server"<<endl; SThread *s_thread = new SThread(); //server thread QObject::connect(s_thread, SIGNAL(test_go(QString)), &aw, SLOT(on_test_go(QString))); //communications between the children thread and UI in main thread s_thread->start(); } if(uw.if_show){ //this is a user cout<<"starts user"<<endl; } return a.exec();} @
-