1111111111111111111111111111111111111111111111111111111111111111111
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
class QPushButton;
class MainWindow : public QWidget {
Q_OBJECT // 只要定義有信號(hào)和槽的類,都得先引用這個(gè)宏.
public :
MainWindow();
~MainWindow();
public slots : // 槽的定義
void myExit();
signal : // 信號(hào)的定義
private :
QPushButton* button;
};
#endif
22222222222222222222222222222222222222222222222222222222222222222
#include <QPushButton>
#include "MainWindow.h"
MainWindow::MainWindow() {
this->setMinimumSize(400, 600);
// button
button = new QPushButton("Das Button", this);
button->resize(200, 50);
QObject::connect(button, SIGNAL(clicked()), this, SLOT(myExit()));
}
MainWindow::~MainWindow() {
delete button;
}
void MainWindow::myExit() {
emit exit(0);
}
333333333333333333333333333333333333333333333333333333333333333333333
#include <QApplication>
#include <QWidget>
#include "MainWindow.h"
int main(int argc, char** argv) {
QApplication app(argc, argv);
MainWindow window;
window.show();
return app.exec();
}
.pro file
TEMPLATE = app
CONFIG += qt warn_on
HEADERS = MainWindow.h
SOURCES = main.cpp
TARGET = test
QTDIR_build:REQUIRES="contains(QT_CONFIG, small-config)"
因?yàn)橛行盘?hào)和槽,所以對(duì)MOC文件的產(chǎn)生有些特殊,因?yàn)榇蠖鄶?shù)時(shí)候都得自定義槽,所以可以作為標(biāo)準(zhǔn)的形式來(lái)操作:
qmake -project
qmake
make
搞定. 差點(diǎn)搞得吐血