Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling quit() method of QApplication

Tags:

qt

if i try to use quit() method directly, it is compiling perfectly, however during runtime there comes an error saying "Object::connect: No such slot myClass::quit()." so to avoid this, is there any way? by using a method quitPicture()(defined as slot) the application is working fine. is this the only solution?

myClass::myClass(QWidget *parent)
    : QWidget(parent)
{
    QWidget *window = new QWidget;
    window->setWindowTitle(QObject::tr("Class"));

    QPushButton *quitButton = new QPushButton("&Quit");
//    QObject::connect(quitButton, SIGNAL(clicked()), this, SLOT(quit()));      //showing run time error
    QObject::connect(quitButton, SIGNAL(clicked()), this, SLOT(quitPicture())); //working perfectly

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(this);
    layout->addWidget(quitButton);
    window->setLayout(layout);
    window->show();
}

void myClass::quitPicture()
{
    std::cout << "calling quitPicture" << std::endl;
    QApplication::quit();
}
like image 349
suma Avatar asked Feb 23 '13 13:02

suma


1 Answers

The button's clicked signal can be connected directly to the application's quit slot:

QObject::connect(quitButton, SIGNAL(clicked()),
                 QApplication::instance(), SLOT(quit()));
like image 163
Daniel Vérité Avatar answered Sep 29 '22 08:09

Daniel Vérité