[Qt-interest] application won't terminate
Kurtis Nusbaum
klnusbaum at gmail.com
Tue Jan 5 00:52:10 CET 2010
Fernec, isn't it weird that the qApp->quit() doesn't work? I had actually
tried that solution before but like you found, I couldn't get it to work
either. Your last solution works I'm sure, but it's not the clean close that
I'd like to see. I do some special clean up as evidenced by my closeEvent
function.
Marek, putting the check in the constructor doesn't seem to work.
-Kurtis
On Sun, Jan 3, 2010 at 4:53 PM, Marek Bronowicki <marek at cyberdeus.pl> wrote:
> 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.comhttp://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
> _______________________________________________
> 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/20100104/8e5de920/attachment.html
More information about the Qt-interest-old
mailing list