下面是我的程序:
#include <qapplication.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <qscrollview.h>
class MyMainWindow:public QScrollView
{
public:
MyMainWindow();
private:
QPushButton *b1;
};
MyMainWindow::MyMainWindow()
{
this->setGeometry(100,100,200,100);
b1=new QPushButton("This button is not too\n big for the window!",this);
b1->setGeometry(10,10,180,80);
b1->setFont(QFont("Times",18,QFont::Bold));
addChild(b1);
}
int main(int argc,char **argv)
{
QApplication a(argc,argv);
MyMainWindow w;
w.show();
a.exec();
return 0;
}
以下是报错信息:
[root@202 Scroll]# make
g++ -c -pipe -g -D_REENTRANT -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.1.0/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.1.0/include/QtCore -I/usr/local/Trolltech/Qt-4.1.0/include/QtGui -I/usr/local/Trolltech/Qt-4.1.0/include -I. -I. -o Scroll.o Scroll.cpp
Scroll.cpp:4:25: qscrollview.h: 没有那个文件或目录
Scroll.cpp:7: parse error before `{' token
Scroll.cpp:15: invalid use of undefined type `class MyMainWindow'
Scroll.cpp:6: forward declaration of `class MyMainWindow'
Scroll.cpp: In constructor `MyMainWindow::MyMainWindow()':
Scroll.cpp:16: invalid use of undefined type `class MyMainWindow'
Scroll.cpp:6: forward declaration of `class MyMainWindow'
Scroll.cpp:17: `b1' undeclared (first use this function)
Scroll.cpp:17: (Each undeclared identifier is reported only once for each
function it appears in.)
Scroll.cpp:17: no matching function for call to `QPushButton::QPushButton(const
char[44], MyMainWindow* const)'
/usr/local/Trolltech/Qt-4.1.0/include/QtGui/qpushbutton.h:87: candidates are:
QPushButton::QPushButton(const QPushButton&)
/usr/local/Trolltech/Qt-4.1.0/include/QtGui/qpushbutton.h:45:
QPushButton::QPushButton(const QIcon&, const QString&, QWidget* = 0)
/usr/local/Trolltech/Qt-4.1.0/include/QtGui/qpushbutton.h:44:
QPushButton::QPushButton(const QString&, QWidget* = 0)
/usr/local/Trolltech/Qt-4.1.0/include/QtGui/qpushbutton.h:43:
QPushButton::QPushButton(QWidget* = 0)
Scroll.cpp:20: `addChild' undeclared (first use this function)
Scroll.cpp: In function `int main(int, char**)':
Scroll.cpp:26: aggregate `MyMainWindow w' has incomplete type and cannot be
defined
make: *** [Scroll.o] Error 1
我用的是QT4.1.0,请问是不是已经没有QScrollView类了?