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();
}
The button's clicked
signal can be connected directly to the application's quit
slot:
QObject::connect(quitButton, SIGNAL(clicked()),
QApplication::instance(), SLOT(quit()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With