Open Hlongyu opened 2 months ago
Check that the DLLs for jpeg and webp libs are deployed and found, too. When it comes to plugins, deployment of transitive runtime dependencies is ... tricky.
Check that the DLLs for jpeg and webp libs are deployed and found, too.
Directory: D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats
Mode LastWriteTime Length Name
-a--- 2024/8/30 10:39 130560 qgifd.dll -a--- 2024/8/30 10:49 157696 qicnsd.dll -a--- 2024/8/30 10:39 137216 qicod.dll -a--- 2024/8/30 10:39 162816 qjpegd.dll -a--- 2024/8/30 10:49 97280 qtgad.dll -a--- 2024/8/30 10:49 93184 qwbmpd.dll -a--- 2024/8/30 10:49 105984 qwebpd.dll
These are the Qt plugins. Some plugins need DLLs with the actual implementation.
When i debug step by step. I found it will call LoadLibrary() for qjpegd.dll.
hnd = LoadLibrary(reinterpret_cast<const wchar_t*>(QDir::toNativeSeparators(attempt).utf16()));
Loaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qjpegd.dll'. Symbols loaded.
Unloaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qjpegd.dll'.
That's just the same information as in the initial post: It fails to load the plugin. But the plugin is there. I already suggest that it might be failing because the plugin fails find runtime dependencies (DLLs), here the jpeg DLL from port libjpeg-turbo.
apart from qjpeg.dll
, you also need copy jpeg62.dll
into your .exe
folder to support jpeg
as for 'webp', you need copy libsharpyuv / libwebp / libwebpdecoder / libwebpdemux / libwebpmux
.
you can find those necessary dependencies in corresponding CMakeLists.txt
in https://github.com/qt/qtimageformats/blob/dev/src/plugins/imageformats
jpeg is provided by Qt::Gui which is part of qtbase, not qtimageformats. Make sure you have the jpeg
feature turned on for qtbase
, and in case you're running from the build directory instead of fully deploying, either set the
QT_PLUGIN_PATH
to $vcpkg_installed/$triplet/debug/Qt6/plugins
or $vcpkg_installed/$triplet/Qt6/plugins
depending on whether you're in debug mode or not. The debug version of the plugins cannot be loaded by a release build nor can the release plugins be loaded by a debug build, so be sure they match.
In case you're using a static build, you might need to tell Qt to bundle the Qt::QJpegPlugin
and Qt6::QWebpPlugin
into your application target(s). If you're dynamic linking , listing Qt::QJpegPlugin
and Qt6::QWebpPlugin
as library dependencies will instruct vcpkg to copy the qt jpeg and webp libraries into your build directory, which is useless because you need them in a subdirectory, but it'll also copy all dependencies of the plugins into the build directory and is aware of whether you're building release or debug, which might be handy.
TLDR: adding something like
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>$<IF:$<STREQUAL:${BUILD_SHARED_LIBS},SHARED>,DLL,>")
enable_testing()
add_test(NAME QtImageFormatTest COMMAND QtImageFormatTest -platform minimal COMMAND_EXPAND_LISTS)
set_property(TEST QtImageFormatTest PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/debug>/bin")
set_property(TEST QtImageFormatTest APPEND PROPERTY ENVIRONMENT_MODIFICATION "QT_PLUGIN_PATH=set:${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/debug>/Qt6/plugins")
qt_import_plugins(
QtImageFormatTest
INCLUDE Qt::QJpegPlugin Qt6::QWebpPlugin Qt::QMinimalIntegrationPlugin
)
should add a ctest target for your application, which configures the environment to load plugins and dlls from vcpkg's intermediate directory prior to executing the binary, bundle the jpeg and webp plugins incase of static linking, and work on either x64-windows
or x64-windows-static
. The _VCPKG_INSTALLED_DIR
and VCPKG_TARGET_TRIPLET
cmake variables are both defined in the vcpkg cmake toolchain file, and the generator expression is used to pick the debug subdirectory if required.
Describe the bug QImageReader::supportedImageFormats() not include jpeg and webp
Environment
To Reproduce Steps to reproduce the behavior:
vcpkg.json
main.cpp
CMakeLists.txt
CMakePresets.json
Expected behavior Support jpeg and webp.
Failure logs