Qt5.12.9配置OpenCV3.4.6(MSCV2017)

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated 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

INCLUDEPATH += \
               D:\\OpenCV3.4.6_2.4.13\\opencv3.4.6\\opencv\\build\\include\\opencv2 \
               D:\\OpenCV3.4.6_2.4.13\\opencv3.4.6\\opencv\\build\\include\\opencv  \
               D:\\OpenCV3.4.6_2.4.13\\opencv3.4.6\\opencv\\build\\include

LIBS += \
        D:\\OpenCV3.4.6_2.4.13\\opencv3.4.6\\opencv\\build\\x64\\vc14\\lib\\opencv_world346.lib \
        D:\\OpenCV3.4.6_2.4.13\\opencv3.4.6\\opencv\\build\\x64\\vc14\\lib\\opencv_world346d.lib \
        D:\\OpenCV3.4.6_2.4.13\\opencv3.4.6\\opencv\\build\\x64\\vc15\\lib\\opencv_world346.lib  \
        D:\\OpenCV3.4.6_2.4.13\\opencv3.4.6\\opencv\\build\\x64\\vc15\\lib\\opencv_world346d.lib


SOURCES += \
    main.cpp \
    mainwindow.cpp

如上代码所示在INCLUDEPATH以及LIBS中设置自己的opencv相应的路径。

注意事项:

  1. 路径要用\\,设置完后应先qmake一下,再运行
  2. 相应的系统环境变量要配置好
  3. Qt5.12.9配置OpenCV3.4.6(MSCV2017)_第1张图片
  4. 出现程序异常退出(没有编译报错)时,重启电脑即可
  5. 出现 “stddef.h”: No such file or directory报错时,重新安装vs2017

你可能感兴趣的:(Qt自学,日常所遇问题总结,qt,c++,opencv)