Blocking main thread, How?
Hi all,
What are ways for blocking main thread?? I want to check for database connection in main thread before showing anything (e.g. mainwindow). There is some limitations:
I have a qml file which i show it before mainwindow and actually is my splash screen, i want to show database connection status on it so while blocking main thread, it have to be active and not blocked.
while blocking i want to run a thread to check database connection in interval ( the splash screen (qml file) is showing the progress).
the main.cpp is something like this:
Code:
int main(int argc, char *argv[])
{
//-------------------------Load-SPLASH
QQuickView splash;
splash.
setSource(QUrl("qrc:/qml/TSplashScreen.qml"));
splash.show();
app.processEvents();
//Check if database is not connected
TInitialDBConnectionCheck initializeDBCheck;
if(!initializeDBCheck.isDBConnected())
{
//Here i have to block main thread and start a thread to check database status intevally. i know how to deal with second but i don't know how to block main thread to stay here while database is ready.
}
MainWindow mw;
splash.close();
mw.showFullScreen();
return app.exec();
}
In addition there is a method called exec() in dialog that do whatever i want !!! but i have here a qml file and a mainthread and another custom thread!
Re: Blocking main thread, How?
QMutex, QWaitCondition. But then ask yourself whether you need it at all. Why not just move your extra thread logic into the main thread?
Re: Blocking main thread, How?
Thanks,
I want to check database connection for every one second(if is disconnected) until connection established. So it seems it have to be done in a thread. That's right?
Re: Blocking main thread, How?
No, what does it change to have a thread here?
Re: Blocking main thread, How?
so how to use a loop for every second in main thread?
Re: Blocking main thread, How?
It depends whether you can afford running an event loop or not. If yes, then use a timer, if no then use sleep().