按照例子在QDevelop中建立一Widget工程,并加入代码
#include <QApplication>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
#include <qfont.h>
class MyWidget : public QWidget
{
public:
MyWidget( QWidget *parent=0, const char *name=0 );
};
MyWidget::MyWidget( QWidget *parent, const char *name )
: QWidget( parent, name )
{
setMinimumSize( 200, 120 );
setMaximumSize( 200, 120 );
QPushButton *quit = new QPushButton("Quit", this, "quit");
quit->setGeometry( 62, 40, 75, 30 );
quit->setFont( QFont( "Times", 18, QFont::Bold ) );
connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
}
int main( int argc, char **argv )
{
QApplication a( argc, argv );
MyWidget w;
w.setGeometry(100, 100, 200, 120);
a.setMainWidget( &w );
w.show();
return a.exec();
}
编译报错,仔细查看/usr/include/qt4/Qt/qpushbutton代码,发现有
#ifdef QT3_SUPPORT
QT3_SUPPORT_CONSTRUCTOR QPushButton(QWidget *parent, const char* name);
QT3_SUPPORT_CONSTRUCTOR QPushButton(const QString &text, QWidget *parent, const char* name);
这个构造函数在QT3中才支持,QT4已废弃,为了兼容可在代码第一行加入#define QT3_SUPPORT,就可以编译通过了
另外Widget.pro中也有设置代码
TEMPLATE = app
SOURCES += src/widg.cpp
指名模板类型和源代码路径