qt 事件学习1

#ifndef QTEST_H
#define QTEST_H
#include<QWidget>
#include<QPushButton>
class QTest: public QWidget{
    Q_OBJECT
public :
        QTest();
private slots:
        void buttonClicked();
private:
        QPushButton *bt;
};

#endif // QTEST_H

#include<QString>
#include<QApplication>
#include<QWidget>
#include<QPushButton>
#include<QMessageBox>


#include  "QTest.h"
QTest::QTest(){
    bt=new QPushButton("bt click",this);
    connect(bt,SIGNAL(clicked()),this,SLOT(buttonClicked()));
}

void QTest::buttonClicked(){
    QMessageBox::about(this,"确认","this is a event");
}

int main(int argc,char ** argv){
    QApplication App(argc,argv);
    QTest t;
    t.show();   
    return App.exec();
}

你可能感兴趣的:(java,qt)