#include <QtGui>#include <QApplication>#include <QPushButton>class Counter : public QObject{ Q_OBJECT public slots: void MessageShow(int value); };void Counter::MessageShow(int value){ QMessageBox* pmbx = new QMessageBox(QMessageBox::Information, "MessageBox", "Simple Message", QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel ); int n = pmbx->exec(); delete pmbx;}int main(int argc, char* argv[]){ QApplication app(argc, argv); Counter a; QWidget wgt; QPushButton* pcmd = new QPushButton ("&Button"); QObject::connect(pcmd,SIGNAL(clicked()),a, SLOT(MessageShow())); //Layout setup QVBoxLayout* pvbxLayot = new QVBoxLayout; pvbxLayot ->addWidget(pcmd); wgt.setLayout(pvbxLayot); wgt.show(); return app.exec();}
C++ (Qt)QObject::connect(pcmd,SIGNAL(clicked()),&a, SLOT(MessageShow()));
C++ (Qt)QMessageBox *msgBox = new QMessageBox();msgBox->setText("Message"); QPushButton* pcmd = new QPushButton ("&Button"); QObject::connect(pcmd,SIGNAL(clicked()),msgBox, SLOT(exec()));