Search code examples
c++qtopencvmingw-w64

Trying to build a test with Opencv and QT


Recently build OPENCV 3.4.3 with CMAKE 3.12.4 and MINGW64(32bit) 8.1.0 in Windows 7. Have QT 5.6 and i trying to test this build as QT Console App, but when i compiling with QT only get the message "Press "RETURN" to close this window...".

.PRO file:

CONFIG += c++11
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
OTHER_FILES += test.png
INCLUDEPATH += C:\Users\Test\Desktop\opencv\build\include
LIBS += C:\Users\Test\Desktop\mingw\bin\libopencv_*.dll

main.cpp:

#include <QCoreApplication>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"

using namespace std;

int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);
    cout << "Hello World!" << endl;
    cv::Mat mat;
    mat = cv::imread("test.png");
    cvNamedWindow("hello");
    cv::imshow("hello",mat);
    return a.exec();
}

What im doing wrong?


Solution

  • Imo the problem is not in your code, I just run it (using Qt5.5, Win10, openCV 4 and mingw64), even if I had to change cvNamedWindow to cv::namedWindow. I have two hints:

    • did you build openCV with mingw64? If not, do so.
    • are the openCV dlls in the path when you run the application? You can also copy all opencv dlls in the program folder to check that quickly...