#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton b("hello world!");
b.show();
QObject::connect(&b,SIGNAL(clicked()),&app,SLOT(quit()));
return app.exec();
}
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton b("hello world!");
b.show();
QObject::connect(&b,SIGNAL(clicked()),&app,SLOT(quit()));
return app.exec();
}
(1)QObeject是所有类的根。
(2)connect(对象a,动作1,对象b,动作2 );的意思就是当对象a发生动作1的时候,对象b就发生动作2。
(3)有SIGNAL和SLOT的地方,必须要有QOBject,所以是QObject::connect。
(4)还有一种初始化QPushButton的方法:QPushButton *b = new QPushButton("hello world!");,需要注意的是调用就变成b->show();了
(5)为了能够正确的把信号和槽连接起来,信号参数的个数,类型以及它们的顺序必须与槽函数相同并且只需要表明类型就可以了,不必要把变量名写出来。