[Qt-interest] application won't terminate
Kurtis Nusbaum
klnusbaum at gmail.com
Sun Jan 3 19:49:04 CET 2010
My understanding of Qt says the following code should work. I have a
MainWindow that upon startup prompts the user for a password. The password
is then hashed and compared to another hash value. If the two do not match
the application should quit. But for some reason, when I call the close()
function, the Main window will close but the application does not terminate.
Anybody have some ideas? When I call the close function in other places in
my code the program terminates just fine.
Main function:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
w.checkPassword();
return a.exec();
}
MaindWindow CheckPassword Function:
void MainWindow::checkPassword(){
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");
close();
}
}
else{
QMessageBox::critical(this, "Error", "Bad
Password");
close();
}
}
}
MainWindow closeEvent function:
void MainWindow::closeEvent(QCloseEvent *event){
saveSettings();
event->accept();
}
-Kurtis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100103/6192d7ec/attachment.html
More information about the Qt-interest-old
mailing list