[Qt-interest] application won't terminate
Ferenc Stelcz
ferenc at stelcz.hu
Sun Jan 3 22:35:41 CET 2010
On 2010.01.03. 9:52 du., Ferenc Stelcz wrote:
> Ok, 3rd possible solution and then I'm going to sleep for today :) :)
>
> On 2010.01.03. 9:46 du., Ferenc Stelcz wrote:
>> Forgot the other (possible) solution:
>>
>> On 2010.01.03. 7:49 du., Kurtis Nusbaum wrote:
>>>
>>> Main function:
>>> int main(int argc, char *argv[])
>>> {
>>> QApplication a(argc, argv);
> ++ a.setQuitOnLastWindowClosed(true); //But this should already be set to
> true by default.
>>> MainWindow w;
>>> w.show();
>>> w.checkPassword();
>>> return a.exec();
>>> }
>>>
>>>
>>
>> --
>> Ferenc Stelcz
>> Ventyx Asset Suite 6 systems administrator
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
Wow... after not having used Qt for more than a 3/4 of a year I forgot
everything I knew.
So all of the 3 solutions won't work. Tried it with 4.5... :/
I have refactored your code a bit and I seem to finally have a working (or at
least a workaround like) program:
MainWindow code:
bool MainWindow::checkPassword()
{
bool retval = true;
if(passwordHash.isEmpty())
{
setupNewPassword();
}
else
{
bool ok = true;
QString passwordInput = QInputDialog::getText(
this,
tr("Enter password"),
tr("Password:"),
QLineEdit::Password,
QString(),
&ok
);
if(ok)
{
QByteArray inputHash = QCryptographicHash::hash(
passwordInput.toUtf8(),
QCryptographicHash::Sha1
);
if(inputHash != passwordHash)
{
QMessageBox::critical(
this,
"Error",
"Incorrect Password"
);
retval = false;
}
}
else
{
QMessageBox::critical(
this,
"Error",
"Bad Password"
);
retval = false;
}
}
return retval;
}
Your main function:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow w;
w.show();
if(!w.checkPassword())
{
return -1;
}
return app.exec();
}
More information about the Qt-interest-old
mailing list