Qt5如何安装与使用

我下载了Qt5.1.1for windows 64-bit(VS2012),安装后没办法用,需要配置一血东西吗?而且我照着Qt4教程上写的一个helloworld也没有办法编译,貌似每一句都是错的。求解决

1、安装Qt5
Qt5的安装比Qt4的安装简单多了,我装的是Qt5.4(qt-opensource-windows-x86-mingw491_opengl-5.4.0.exe),它集成了MinGW、Qt Creator等,不需要你再单独下载MinGW和Qt Creator。
首先,去Qt官网下载资源:qt-opensource-windows-x86-mingw491_opengl-5.4.0.exe;然后,双击安装即可。安装后,“开始”菜单

2、配置Qt
打开Qt Creator,工具–>选项,打开“选项”对话框
若没有检测出,则添加相应的Qt版本和编译器(MinGW),再设置构建套件(Kits):设备类型、编译器(MinGW)、调试器、Qt版本
3、使用Qt
打开Qt Creator,新建项目–>其他项目–>空的qmake项目,项目命名为“QtTest”,再添加新文件main.cpp。
在main.cpp中添加如下代码:
#include<QApplication>
#include<QVBoxLayout>
#include<QLabel>
#include<QPushButton>

int main(int argc,char *argv[])
{
QApplication app(argc,argv);

QWidget *window = new QWidget;
window->setWindowTitle("QtTest");

//QLabel *label= new QLabel("Hello Qt");
QLabel *label = new QLabel("<h2><i>Hello</i>"" <font color = red>Qt</font><h2>");

QPushButton *button=new QPushButton("Quit");
QObject::connect(button,SIGNAL(clicked()),&app,SLOT(quit()));

QVBoxLayout *layout=new QVBoxLayout;
layout->addWidget(label);
layout->addWidget(button);
window->setLayout(layout);

window->show();

return app.exec();
}
此时,代码显示如下错误:

运行时错误提示:#include<QApplication>–No such file……
实际上,QT5中很多常用的QT头文件都被移到core gui widgets 等模块中去了,在QT5中,.pro文件需要增加额外的一行(注意大小写):
QT += core gui widgets
其中Qt += core gui widgets 表示链接QtCore(d).dll、QtGui(d).dll、QtWidgets(d).dll。
我们在.pro文件中增加一行上述代码,保存,再双击打开.cpp文件,此时错误提示线消失,运行,结果
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-10-03
Qt4和Qt5差别很大,Qt4的代码直接拿到Qt5都不能编译通过。本回答被提问者采纳
第2个回答  2013-09-29
你在win7以上的64位系统里安装vs2012了吗?追问

安装了呀

相似回答