franco.amato
11th May 2011, 19:02
Hi to all,
I would pause the main thread for 2-3 sec and then exit from the application but I can not find a solution.
In my case when application starts a status dialog appears showing some result and then the main window is shown. There is a case where I would wait a couple of seconds ( to give to the user the time to read ) and then exit completely from the application. This is the code I wrote:
void CertiIrisApp::init() //CertiIrisApp is the main application derived class
{
start = new StartDlg(0); // start is a dialog showing some initialization results
start->show();
start->print(QString("> Welcome to CertiIris")); //print prints a message
processEvents();
start->print(QString("> Checking for Iris scanner..."));
if (checkIrisScanner())
{
start->print(QString("> Correct Iris scanner connected."));
processEvents();
}
else
{
QString msg = "> An incorrect iris scanner has been connected, contact author.";
start->print(msg);
processEvents();
Sleep(1); // I would wait to give the time to read
QCoreApplication::exit(1); //and then exit
}
if ( connectToDB() == true )
{
QString str = "> " + QCoreApplication::applicationName() + " is successfully connected to the IrisServer.";
start->print(str);
processEvents();
onLoadDBRecords();
}
else
{
QString str = "> " + QCoreApplication::applicationName() + " could not connected to the IrisServer.";
start->print(str);
processEvents();
}
start->hide(); // hide the dialog
delete start; // and delete it
m_mainWnd->show(); // here I show the main window
return;
}
The problem of my code is that the program flow doesn't wait at the Sleep call and follow showing the next message.
Where is my mistake?
Regards,
Franco
I would pause the main thread for 2-3 sec and then exit from the application but I can not find a solution.
In my case when application starts a status dialog appears showing some result and then the main window is shown. There is a case where I would wait a couple of seconds ( to give to the user the time to read ) and then exit completely from the application. This is the code I wrote:
void CertiIrisApp::init() //CertiIrisApp is the main application derived class
{
start = new StartDlg(0); // start is a dialog showing some initialization results
start->show();
start->print(QString("> Welcome to CertiIris")); //print prints a message
processEvents();
start->print(QString("> Checking for Iris scanner..."));
if (checkIrisScanner())
{
start->print(QString("> Correct Iris scanner connected."));
processEvents();
}
else
{
QString msg = "> An incorrect iris scanner has been connected, contact author.";
start->print(msg);
processEvents();
Sleep(1); // I would wait to give the time to read
QCoreApplication::exit(1); //and then exit
}
if ( connectToDB() == true )
{
QString str = "> " + QCoreApplication::applicationName() + " is successfully connected to the IrisServer.";
start->print(str);
processEvents();
onLoadDBRecords();
}
else
{
QString str = "> " + QCoreApplication::applicationName() + " could not connected to the IrisServer.";
start->print(str);
processEvents();
}
start->hide(); // hide the dialog
delete start; // and delete it
m_mainWnd->show(); // here I show the main window
return;
}
The problem of my code is that the program flow doesn't wait at the Sleep call and follow showing the next message.
Where is my mistake?
Regards,
Franco