初次使用QT,安装时就遇到了一些问题,调试加整理文件用了三天,现在总结出来,希望有所帮助。
最终选择版本:
Windows7+Qt5.9.3(包含QtCreator4.4.1)+VS2013+OpenCV3.3.0+cmake3.10.0
一、 Qt及QtCreator的下载与安装
在资源下载页面(
http://download.qt.io/archive/qt/
)进行下载,这里罗列了多有可用版本,便于选择。根据自己的开发需要,我们这里下载的版本是:qt-opensource-windows-x86-5.9.3.exe
二、 QT安装
运行qt-opensource-windows-x86-5.9.3.exe,下一步即可;
Skip即可;
直接点击下一步;
选择好安装文件夹,建议不要将QT安装在C盘,其他保持默认即可,点击下一步;
下一步是根据需要选择组件,相关的选择标准请参照链接:
https://jingyan.baidu.com/article/656db918d9292ae380249c4f.html
我们这里勾选了MinGW及VS(msvc2013)相关的编译器;Tools全部进行了勾选。
接着,在打开的页面中勾选“我已阅读并同意条款”,然后一路下一步,直到安装完成就可以了。
等待至安装完成。
三、 三、QT creator打开与创建
安装好的QT5.9.3直接包含qt creator4.4.1在内,打开qt creator4.4.1。
点击工具——>选项——>构建与运行——>构建套件——>选择系统自动检测出的编译器并配置编译器如图所示:
点击ok。
新建项目进行编程操作即可。
四、 VS2013与opencv3.3.0配置
参考链接如下:
(1)
http://blog.csdn.net/jinian2614/article/details/78176704
(2)为方便实现永久配置,配置OpenCV3.3动态链接库及以后的操作,参照第二个链接如下:
http://blog.csdn.net/amusi1994/article/details/76768775?locationNum=10&fps=1
五、
QT5.9.3与opencv3.3.0配置
参考链接如下:
https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows
(windows下QT5.9.3与opencv3.3.0配置)需要注意的的地方是,在configure cmake对opencv产生解决方案前,需将cmake的路径:D:\opencv\cmake-3.10.0-rc1-win64-x64\bin(
才开始因解压时未注意,路径为
D:\opencv\cmake-3.10.0-rc1-win64-x64\cmake-3.10.0-rc1-win64-x64\bin
,当用此路径时,或许因路径过长,无法进行
cmake configure
)
及MinGW的路径:D:\Qt\Qt5.9.3\5.9.3\mingw53_32\bin与D:\Qt\Qt5.9.3\Tools\mingw530_32\bin 这三个环境变量都添加至系统环境变量的path中,才能进行的了configure操作。其余详细参照以上链接操作即可。更改QT中文件代码如文件《opencv在QT中配置代码》,详细如下:
modify the .pro file like this:
#————————————————-
#
# Project created by QtCreator2017-03-05T12:30:06
#
#————————————————-
QT
+=
core gui
greaterThan(QT_MAJOR_VERSION,
4
)
:
QT
+=
widgets
TARGET
=
opencvtest
TEMPLATE
=
app
# The following define makes yourcompiler emit warnings if you use
# any feature of Qt which as been markedas deprecated (the exact warnings
# depend on your compiler). Pleaseconsult the documentation of the
# deprecated API in order to know how toport your code away from it.
DEFINES
+=
QT_DEPRECATED_WARNINGS
# You can also make your code fail tocompile if you use deprecated APIs.
# In order to do so, uncomment thefollowing line.
# You can also select to disabledeprecated APIs only up to a certain version of Qt.
#DEFINES +=QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES
+=
main.cpp\
mainwindow.cpp
HEADERS
+=
mainwindow.h
FORMS
+=
mainwindow.ui
INCLUDEPATH
+=D:\opencv\OpenCV_QT\install\
include
#
注意该路径为编译后install内的路径,且该路径不能有空格,不能写错,要仔细
LIBS
+=D:\opencv\OpenCV_QT\bin\libopencv_core330.dll
LIBS
+=D:\opencv\OpenCV_QT\bin\libopencv_highgui330.dll
LIBS
+=D:\opencv\OpenCV_QT\bin\libopencv_imgcodecs330.dll
LIBS
+=D:\opencv\OpenCV_QT\bin\libopencv_imgproc330.dll
LIBS
+=D:\opencv\OpenCV_QT\bin\libopencv_features2d330.dll
LIBS
+=D:\opencv\OpenCV_QT\bin\libopencv_calib3d330.dll
# more correct variant, how setincludepath and libs for mingw
# add system variable:OPENCV_SDK_DIR=D:/opencv/build
# read http:
//doc.qt.io/qt-5/qmake-variable-reference.html#libs
#INCLUDEPATH += $$(OPENCV_SDK_DIR)/include
#LIBS +=-L$$(OPENCV_SDK_DIR)/x86/mingw/lib \
# -lopencv_core320 \
# -lopencv_highgui320 \
# -lopencv_imgcodecs320 \
# -lopencv_imgproc320 \
# -lopencv_features2d320 \
# -lopencv_calib3d320
and modify mainwindow.cpp like this:
(测试代码)
#include
“mainwindow.h”
#include
“ui_mainwindow.h”
#include
<opencv2/core/core.hpp>
#include
<opencv2/highgui/highgui.hpp>
MainWindow
::
MainWindow(QWidget
*
parent)
:
QMainWindow(parent),
ui(
new
Ui
::
MainWindow)
{
ui
->
setupUi(
this
);
// read an image
cv
::
Mat image
=
cv
::
imread(
“d://1.jpg”
,
1
);
// create imagewindow named “My Image”
cv
::
namedWindow(
“My Image”
);
// show theimage on window
cv
::
imshow(
“My Image”
, image);
}
MainWindow
::~
MainWindow()
{
delete
ui;
}
笔者因为粗心,在前面.pro文件中的
INCLUDEPATH
+=D:\opencv\OpenCV_QT\install\
include 路径中复制入了空格,运行时始终提示
opencv2/core/core.hpp…NO such file 等信息,无法运行成功,一定要仔细。