PDA

View Full Version : How to access Quit Slot without aplication pointer...



Cayan
23rd April 2009, 03:05
How can I simple open a program perform some actions and then close it?
Already tried:
QTimer::singleShot(10, &a, SLOT(quit()) );
Inside the mainform... but I do not have access to the application pointer...


Base code for what I want:

msgBox.setText("Bla bla bla");
QPushButton *opt1 = msgBox.addButton(tr("First One!"), QMessageBox::ActionRole);
QPushButton *opt2 = msgBox.addButton(tr("Second One!"), QMessageBox::ActionRole);
msgBox.setDefaultButton(opt2);
msgBox.setIcon(QMessageBox::Warning);
msgBox.exec();

if(msgBox.clickedButton() == opt1)
{
//some actions...
//Close the entire program!
}

Cayan
23rd April 2009, 04:02
By the way.. we cant forget that Qt still is C++ related so...
this solves everything:

exit ( 0 );

thanks anyway :)

Lykurg
23rd April 2009, 07:15
exit ( 0 );
That's a bad way to exit a GUI app. If you need a pointer to your application use QCoreApplication::instance() or the short hand qApp.