Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT + OpenCV + CMake + MSVC2019 Compatibility Issues



  • Hello all,

    My Computer version is Windows 10, 64-bit Operating System
    However I will be creating a 32 bit Widget Application with OpenCV

    I have the following versions installed in my computer

    QT 5.12.6 (Everything under the Tab)
    OpenCV 4.1.2 (Extracted from .exe file to a Folder)
    CMake 3.16.2-win32-x86 (Should it be x64 as my PC is 64bit)?
    MSVC2019 Version 16.3.7

    What are you thoughts? Will there be incompatibility issues between the versions when I try to use CMake to Interface OpenCV with MSVC2019?
    If there are incompatibilities, what are the recommended versions to use?

    I tried the following tutorial (via link)
    https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows_with_MSVC2017#CMake

    I followed closely to their versions. However, there are errors when i use CMake to Configure QT with OpenCV (libraries aren't linked). Any reasons why?


  • Qt Champions 2019

    @Stevendragoes said in QT + OpenCV + CMake + MSVC2019 Compatibility Issues:

    However, there are errors when i use CMake to Configure QT with OpenCV (libraries aren't linked). Any reasons why?

    You should tell what errors exactly.


  • Moderators

    @Stevendragoes said in QT + OpenCV + CMake + MSVC2019 Compatibility Issues:

    OpenCV 4.1.2 (Extracted from .exe file to a Folder)

    Which compiler was used to build this version of OpenCV 4.1.2? 32-bit or 64-bit?

    QT 5.12.6 (Everything under the Tab)

    You don't need everything under the tab. You only need the one version that uses the same compiler as the OpenCV build.



  • @jsulm I am sorry I didn't take the screenshot of the errors
    @JKSH Hello I used MSVC2017 to compile and build OpenCV4.1.2 in 32-bit Debug Mode
    Was it my choice of CMake Versions?

    I just installed everything over the night. Hopefully it works now.


  • Moderators

    @Stevendragoes said in QT + OpenCV + CMake + MSVC2019 Compatibility Issues:

    I am sorry I didn't take the screenshot of the errors

    The error information will help you track down and solve the problem. if the error happens again, capture it.

    Hello I used MSVC2017 to compile and build OpenCV4.1.2 in 32-bit Debug Mode

    Then you need to install Qt for MSVC201x 32-bit. You don't need the others.

    Note: If you only have the Debug version of OpenCV, then you can only use the Debug version of Qt. You cannot use the Release version.

    Was it my choice of CMake Versions?

    I don't think the CMake version matters, as long as you are using a reasonably recent version.

    (Should it be x64 as my PC is 64bit)?

    No, that is fine. A 64-bit PC can run 32-bit applications.



  • Hi @JKSH
    76b1b14c-69a5-4f6a-a04e-3f3b0d2ac3a4-image.png

    This is the error I got. The directory is not found. any reasons why? I have installed QT5.12.6 and I used the Visual Studio 15 2017 to configure opencv libraries


  • Moderators

    @Stevendragoes said in QT + OpenCV + CMake + MSVC2019 Compatibility Issues:

    This is the error I got. The directory is not found. any reasons why?

    Read the error message carefully. It tells you how to fix it. ("Add the installation prefix...")

    Also, go through https://doc.qt.io/qt-5/cmake-get-started.html



  • @JKSH Hello again.
    If I am not wrong, the guide was meant for an application if I were to use CMake as a compiler.
    However, I am using qmake as my compiler as I am building a GUI application. I just want CMake to Generate an OpenCV.sln with QT so that I can link the libraries of OpenCV to QT.
    And I think I have found the error.
    My best guess is that I didn't link the PATH in my environment variable and REBOOT

    And To all who are having issues installing OpenCV and QT, I followed this guide step by step

    https://github.com/MicrocontrollersAndMore/OpenCV_3_Windows_10_Installation_Tutorial/blob/master/Installation Cheat Sheet 4 - OpenCV 3 Compile From Source and Qt.pdf

    Now, My QT can type OpenCV languages like Mat, imshow, imread etc..

    My Current Working Specs are as follows
    QT 5.12.6 (MSVC2017 32bit)
    OpenCV 4.1.2 (Extracted from .exe file to a Folder)
    CMake 3.16.2-win32-x86
    MSVC2017 (if you have error of corecrt.h not found, follow the below link and install Universal CRT SDK)

    MSVC2019 wasn't supported in QT5.12.6 which is the latest LTS.


  • Moderators

    @Stevendragoes said in QT + OpenCV + CMake + MSVC2019 Compatibility Issues:

    And I think I have found the error.

    Great!

    If I am not wrong, the guide was meant for an application if I were to use CMake as a compiler.

    CMake and qmake are build tools. MSVC is your compiler.

    However, I am using qmake as my compiler as I am building a GUI application.

    You can use either CMake OR qmake to build GUI applications.

    My best guess is that I didn't link the PATH in my environment variable and REBOOT

    It is best to avoid putting libraries in the PATH because this might cause DLL Hell. Instead, configure your project to tell it where to find your libraries.

    For my 64-bit qmake project, I put this in my *.pro file:

    INCLUDEPATH += C:/tools/opencv/build/include/
    
    LIBS += \
        -LC:/tools/opencv/build/x64/vc15/lib \
        -LC:/tools/opencv/build/x64/vc15/bin
    
    CONFIG(debug, debug|release) {
        LIBS += -lopencv_world411d
    }
    CONFIG(release, debug|release) {
        LIBS += -lopencv_world411
    }
    

    MSVC2019 wasn't supported in QT5.12.6 which is the latest LTS.

    MSVC 2015, 2017, and 2019 are all compatible with each other. You can use Qt 5.12.6 for MSVC 2017 with the compiler from Visual Studio 2019.


  • Qt Champions 2019

    @Stevendragoes said in QT + OpenCV + CMake + MSVC2019 Compatibility Issues:

    if I were to use CMake as a compiler.
    However, I am using qmake as my compiler as

    neither cmake nor qmake are compilers.

    MSVC2019 wasn't supported in QT5.12.6 which is the latest LTS.

    msvc2017 is compatible with msvc2019 so it was supported.



  • Thanks @Christian-Ehrlicher and @JKSH

    Turns out I still faced an error it is something like this
    https://forum.qt.io/topic/65902/cannot-open-include-file-corecrt-h-no-such-file-or-directory

    I tried their methods I couldn't solve the error.
    Hence, I am reinstalling Microsoft Visual Studio 2017 now.
    42f76d8b-1084-4b5a-9d97-0804a89b9727-image.png

    Meanwhile, it will be great if you don't mind clarifying my doubts?

    1. Microsoft Visual Studio Community 2017 is needed as a KIT to create Widgets Application under QT Creator?
    2. Compilers can be MSVC2019 when I press Manage and under Compilers.
    3. What about the Debuggers? should I use MinGW debugger? I need more information about them.


  • Hello again @JKSH or everyone,

    Is it better to use QT Creator to create my Application or Microsoft Visual Studio 2019?
    Or should I use Microsoft Visual Studio 2017? I will use QT Widgets for my GUI application?

    As I already installed Plugins for MSVC 2019. When I tried to create the GUI Application, it says that I need to specify the BUILD of QT. I already have QT 5.12.6 installed.



  • I have ended up using Microsoft Visual Studio 2017 to Build my Application with QT Plugin As I was unable to link the Windows Kit Header Files to QT Creator. The Results are As Follows.

    d9be22b3-e0e1-4041-9f03-4a74dd264cc7-image.png

    Then from the Project File Properties, I can link all the libraries of OpenCV to be incorporated to the project file.
    Let me know what you guys think



  • @Stevendragoes Hello Steven,

    Let me help you how I build OpenCV-4.3.0 from source with MSVC2019 ver.16.5.4 and then how I added OpenCV to Qt Creator

    1. After successful build and installation of OpenCV source binaries I have added to System Environment - System Variables Path the .dll files for Release and Debug separately.
    C:\opencv-4.3.0\build_MSVC\bin\Release
    C:\opencv-4.3.0\build_MSVC\bin\Debug
    
    1. Create a new project in Qt Creator and edit the .pro file as follows:
    INCLUDEPATH += C:\opencv-4.3.0\build_MSVC\install\include
    
    LIBS += -LC:\opencv-4.3.0\build_MSVC\install\x64\vc16\lib
    
    CONFIG(debug, debug|release) {
        LIBS += -lopencv_core430d -lopencv_highgui430d -lopencv_imgcodecs430d -lopencv_imgproc430d -lopencv_video430d -lopencv_videoio430d
    }
    CONFIG(release, debug|release) {
        LIBS += -lopencv_core430 -lopencv_highgui430 -lopencv_imgcodecs430 -lopencv_imgproc430 -lopencv_video430 -lopencv_videoio430
    }
    
    1. On the left of the left side bar in Qt Creator click on Projects.
      Under the Build & Run go to Run section and check the Environment group on the right.
      Base Environment for this configuration : System Environment
      click on Details and check out the Path variable and make sure that the .dll paths for Release and Debug is there. If not press Edit and manually add the paths as stated in Step 1.

    That's it. You can add any third party library the similar way.

    Hope it helps.

    D.Maya


Log in to reply