Hi:
I've successfully built the OpenCV 4.8.0 library in static library mode with the Qt option using vcpkg.
vcpkg.exe install opencv[ade,contrib,default-features,dnn,eigen,ffmpeg,freetype,gdcm,jasper,jpeg,lapack,nonfree,openexr,opengl,openmp,ovis,png,python,qt,quirc,sfm,tbb,tiff,vtk,vulkan,webp]:x64-windows-static --recurse
Then I created a windows application in Visual C++ 2019 using Win32 API and successfully linked all the necessary libraries to make a standalone executable.
The app starts correctly and allows me to select an image to be opened using cv::imread()
which successfully reads the image but them when I try to display the image using cv::imshow()
, I get the error dialog that says
This application failed to start because no Qt platform plugin could be initialized.
I've tried using windeployqt.exe like this:
\vcpkg\installed\x64-windows-static\tools\Qt6\bin\windeployqt.exe --debug --compiler-runtime "\Projects\Test\appName\x64\Debug\appName.exe"
but it complains:
\Projects\Test\appName\x64\Debug\appName.exe does not seem to be a Qt executable.
and does not copy anything into that folder. I've also tried coping "\vcpkg\installed\x64-windows-static\Qt6\plugins\platforms" into my executable and project folder, but I still get the same platform initialization error.
I also need to mention that my code does NOT use Qt in any way directly. Only OpenCV uses it and I've no intention of learning Qt or using it to make an app.
I've also set the project's Properties -> Debug -> Environment to:
PATH=%PATH%;D:\vcpkg\installed\x64-windows-static\tools\Qt6\bin\;D:\vcpkg\installed\x64-windows-static\Qt6\plugins\;D:\vcpkg\installed\x64-windows-static\Qt6\plugins\platforms\;
None of these steps helped. Anyone knows how I get passed this problem?
Well, I was able to figure it out myself (kind of).
The short answer is that in the same Platform
directory, you can find qwindows.lib which you should link with your app. Then you'll have to include a header file and add this line:
#include <Qt6/QtCore/qplugin.h>
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
But that is not where the problem ends. Now when you try to compile the application, you'll get lots of unresolved linker error. In order to fix those, you'll have to link these additional libraries:
Qt6OpenGL
Netapi32
D3D9 (in addition to D3D11 and D3D12 that you had to link for OpenCV)
freetype
bz2
brotlidec
brotlicommon
Wtsapi32"
Imm32
Setupapi
Shcore
UxTheme
Dwmapi
runtimeobject
After you link all of that, cv::imshow
kind of starts working, but as you can see in the 1st attached screenshot below, the toolbar is text only and does not have the pretty icons that it supposed to, and the tool buttons work but very slowly. For example, it would be much faster to use mouse wheel to zoom in and out. The window can be resized to show more toolbar buttons.
If you try to use cv::namedWindow("Input", cv::WINDOW_OPENGL);
, you'll get multiple assertion errors like 2nd screenshot.
The status bar works, but I'm already thinking of getting rid of Qt option if it is going to look ugly like this (unless of course someone know how to fix that).