有这样一段Qt3程序:
#include <qapplication.h>
#include<qhbox.h >
#include <qslider.h>
#include<qspinbox.h>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QHBox *hbox = new QHBox(0);
hbox->setCaption("Enter your Age");
hbox->setMargin(6);
hbox->setSpacing(6);
QSpinBox *spinbox = new QSpinBox(hbox);
QSlider *slider = new QSlider(Qt::Horizontal,hbox);
spinbox->setRange(0,130);
slider->setRange(0,130);
QObject::connect(spinbox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(slider,SIGNAL(valueChanged(int)),spinbox,SLOT(setValue(int)));
spinbox->setValue(35);
app.setActiveWindow(hbox);
hbox->show();
return app.exec();
}
我使用的IDE是 Codeblocks,建立了一个QT4工程,编译上述代码,提示没有#include<qhbox.h> 这个文件,所以QHBox就不能用了。
查了一下,把 源代码改为如下:
#include <qapplication.h>
#include<q3hbox.h>// 更改
#include <qslider.h>
#include<qspinbox.h>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
Q3HBox *hbox = new Q3HBox(0);//更改
hbox->setCaption("Enter your Age");
hbox->setMargin(6);
hbox->setSpacing(6);
QSpinBox *spinbox = new QSpinBox(hbox);
QSlider *slider = new QSlider(Qt::Horizontal,hbox);
spinbox->setRange(0,130);
slider->setRange(0,130);
QObject::connect(spinbox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(slider,SIGNAL(valueChanged(int)),spinbox,SLOT(setValue(int)));
spinbox->setValue(35);
app.setActiveWindow(hbox);
hbox->show();
return app.exec();
}
头文件没问题了,但是又提示没有setCaption()这个成员函数。
于是,就使用Qt creator建立一个工程,建立的时候勾选 qt3support ,编译上述第一个代码,还是同样的问题,找不到头文件。不过第二个在Qt creater下还是可以运行。
感觉有点乱套,不知有没有人碰到过类似问题,有没有较好的办法,不用改来改去的,刚刚接触QT,希望达人指点一二,先谢谢~
[ 此帖被renjianke在2010-01-18 09:53重新编辑 ]