[Qt-interest] application won't terminate

Marek Bronowicki marek at cyberdeus.pl
Sun Jan 3 23:53:33 CET 2010


Try to move w.checkPassword() inside the MainWindow constructor.


W dniu 2010-01-03 19:49, Kurtis Nusbaum pisze:
> 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
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>    

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100103/4e0f7336/attachment.html 


More information about the Qt-interest-old mailing list