//.c文件
#include <QApplication>
#include <QPushButton>
#include <QString>
#include "main.h"
void MyWidget::setnum()
{
num++;
// str = new QString;
str.setNum(num);
b1->setText(str);
}
MyWidget::MyWidget(QWidget *parent):QWidget(parent)
{
num = 0;
b1 = new QPushButton(tr("0"), this);
// b1 = new QPushButton(this);
b1->setGeometry(10, 10, 100, 100);
b1->setFont(QFont("Times", 16, QFont::Bold));
// str.setNum(num);
connect(b1, SIGNAL(clicked()), this, SLOT(setnum()));
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWidget widget;
widget.setGeometry(100, 100, 200, 200);
widget.show();
return app.exec();
}
编译:
在qt4下编译给其单独建立一个目录
$ qmake -project
$ qmake
$ make
$ ./15-4
|