学习一:头文件找不到问题(版本变化)
我用的是在windows +vs2005+qt4.3平台
在网上按
Qt教程一 —— 第三章:家庭价值
学习时遇到如下问题:
#include <qapplication.h>参考资料:http://doc.trolltech.com/4.4/classes.html
#include <qpushbutton.h>
#include <qfont.h>
#include <qvbox.h> // 系统找不到这个头文件
经查资料:4.3 已经没有这个类 而是用QVBoxLayout 代替
因此换成#include<QVBoxLayout>就可以了
源程序如下:
- #include <QtGui/QApplication>
- #include <qpushbutton>
- #include<qfont>
- #include <QVBoxLayout>
- using namespace std;
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- QWidget window;
- window.resize(200,120);
- QVBoxLayout layout;
- QPushButton quit("Quit",&window);
- quit.setFont(QFont("Times",18,QFont::Bold));
- QObject::connect(&quit,SIGNAL(clicked()),&a,SLOT(quit()));
- layout.addWidget(&quit);
- window.setLayout(&layout);
- window.show();
- return a.exec();
- }
运行结果如下: