QInputDialog In Main
-
the Following is my code
@#include <QtGui/QApplication>
#include <QInputDialog>
//#include "mydilog.h"
#include <QDebug>int main(int argc,char* argv[])
{QApplication app(argc, argv); bool ok; QString output; output = QInputDialog::getText(NULL, ("QInputDialog::getText()"), ("User name:"), QLineEdit::Normal, "test", &ok); qDebug() << "Ok == " << ok; qDebug() << "output == " << output; app.exec();
}@
How can i quit the Program on from main? i want the app.exec(); but on "Ok" Button click i want to quit from the Main.
How can i Implement this
-
compare the output with "Text to Exit" and call exit() ?
-
I'm not quite sure what "... i want the app.exec() ..." means but if you want to enter the event loop before exiting (for whatever reason) use a singleshot timer.
@
int main(int argc,char* argv[])
{
...qDebug() << "Ok == " << ok; qDebug() << "output == " << output; if(ok == true) QTimer::singleShot(0, &app, SLOT(quit())); return app.exec();
}
@
Otherwise just don't call QApplication::exec().
@
int main(int argc,char* argv[])
{
...qDebug() << "Ok == " << ok; qDebug() << "output == " << output; if(ok == false) return app.exec(); return 0;
}
@ -
[quote author="stuk" date="1328868151"]compare the output with "Text to Exit" and call exit() ?[/quote]
QApplication::quit() and QApplication:exit() does nothing if there is no event loop running (ie. before QApplication::exec() is called).
-
for exit() i mean the stdlib function.
[quote author="Lukas Geyer" date="1328868453"][quote author="stuk" date="1328868151"]compare the output with "Text to Exit" and call exit() ?[/quote]
QApplication::quit() and QApplication:exit() does nothing if there is no event loop running (ie. before QApplication::exec() is called).[/quote]