0

I need to use OpenCV in a Qt application that uses Qbs and QML in Windows

I am using the MVSC2017 (64-bit) compiler that got installed with Qt 5.11

and I have OpenCV 3.41 (I have to link against opencv_world341.lib)

I know it's in C:\opencv\build, but as far as I understand Qbs, I can't use the path from 'C:' (please tell me if I'm wrong here)

I can't change to (C|Q)make, because I will need to integrate the functionality in this application into a bigger application using qbs, and the qml file

I tried using

import qbs

Project {
      CppApplication {
        Depends { name: "Qt.core" }
        Depends { name: "Qt.quick" }
        Depends { name: "OpenCV" }

        cpp.cxxLanguageVersion: "c++11"

        files: [
            "main.cpp",
            "qml.qrc",
        ]

    }
    CppApplication {
         name: "OpenCV"
         cpp.includePaths: ["../../../../../../opencv/build/include/"]
         cpp.libraryPaths: ["../../../../../../opencv/build/x64/vc15/lib/"]
         cpp.staticLibraries: "opencv_world341"
    }
}

I determined the number of ../ with git bash starting from the directory containing the qbs file

but I get the error

C1083: Cannot open include file: 'opencv2/core.hpp': No such file or directory

am I doing something wrong in the Qbs file?

I know the opencv installation works, because I used it in visual studio community 2017 to test it

David-EL
  • 31
  • 1
  • 2

1 Answers1

0

I managed to find the way to do it, there were two problems, the first, is that I was using the Debug build in Qtcreator, with the opencv_world341.lib file, so the linking was not being done correctly, I needed the opencv_world341d.lib file for that, but I didn't want to lose the release build, so I added a Properties blocks so that the static library file would set itself depending on the build type using qbs.buildVariant property

and the second problem, is that separating the include and library paths from the application I was building would not work, so I put it inside the CppApplication Block, and now it works

I changed the qbs file like this:

import qbs

Project {
    CppApplication {
        Depends { name: "Qt.core" }
        Depends { name: "Qt.quick" }
        cpp.includePaths: ["../../../../../../opencv/build/include/"]
        cpp.libraryPaths: [
            "../../../../../../opencv/build/x64/vc15/lib/",
            "../../../../../../opencv/build/x64/vc15/bin/"
        ]
        cpp.cxxLanguageVersion: "c++11"

        Properties
        {
            condition: qbs.buildVariant == "debug"
            cpp.staticLibraries: ["opencv_world341d"]
        }
        Properties
        {
            condition: qbs.buildVariant == "release"
            cpp.staticLibraries: "opencv_world341"
        }

        files: [
            "main.cpp",
            "qml.qrc",
        ]
    }
}
David-EL
  • 31
  • 1
  • 2