Problem when trying to use webp in the app's final executable (Qt 6.4)
-
Hello.
I am trying to use the webp format to save images generated with QImage as follows:
QImage img = QImage(QDir::toNativeSeparators("path/to/local/file")); QImage result = img.scaled(192, 192, Qt::KeepAspectRatio, Qt::SmoothTransformation); QString path = "/some/path/result.webp"; if(!result.save(path, "WEBP", 75)) return;
The "save" function returns true if I launch the app from QtCreator. However, if I build the final executable, the same code returns false.
I have verified that this is not a path/permission access problem, so the only conclusion I can come to is that it is a problem with the webp library.
I've added a few lines to the CMakeLists.txt so that webp is supported and works, at least, from QtCreator.
find_library(WEBP_LIBRARIES webp) target_link_libraries (my-project ${WEBP_LIBRARIES})
Do I need to do anything else to make this work also with the final executable of the app? I'm testing from MacOS right now, but I would like this image format to be supported in the Windows and Linux versions too.
Thanks in advance.
-
@Christian-Ehrlicher @SGaist I think I managed to solve the problem. The problem is that the webp library is not included in the Qt installation directory. I mean, by default, in the path /Users/user/Qt/6.4.2/macos/plugins/imageformats, only the following libraries are included in my case:
libqgif.dylib libqico.dylib libqjpeg.dylib libqsvg.dylib
I understand that for this reason, when macdeployqt generates the final application directory, it does not include the webp library.
However, I have been able to find much more libraries in the path /Users/user/Qt/QtDesignStudio/qt6_design_studio_reduced_version/plugins/imageformats, including the following one:
libqwebp.dylib
All I had to do is to copy libqwebp.dylib
to /Users/user/Qt/6.4.2/macos/plugins/imageformats, build the final project executable again, and it works.Thanks a lot to both of you! :))
-
@Alexuds79 said in Problem when trying to use webp in the app's final executable (Qt 6.4):
find_library(WEBP_LIBRARIES webp)
target_link_libraries (my-project ${WEBP_LIBRARIES})What should this help? By just linking a library it will not magically add some features to Qt.
WebP is supported by Qt through a QImageFormats plugin and you most likely do not distribute the plugin because you don't use windeployqt but do it manually. -
@Christian-Ehrlicher In fact, I use macdeployqt to generate the final executable and the imageformats plugin is inside the final application directory. This is the path to the plugin:
MyApp.app/Contents/PlugIns/imageformats
However, inside this directory, I can't find anything related to webp:
libqgif.dylib libqico.dylib libqjpeg.dylib libqsvg.dylib
-
@Alexuds79 Ok, then as a first check try to add the plugin manually after macdeployqt. If this works we have to investigate why macdeployqt doesn't find out the it also needs the webp image plugin.
-
@Christian-Ehrlicher The webp library is also included in the final directory, in this path:
MyApp.app/Contents/Frameworks/libwebp.7.dylib
I tried copying the library manually to the imageformats directory, but that didn't work either.
-
@Alexuds79 hi,
This is the format library not the plugin. Any in any case, this would not be enough, you need to fix the paths of the plugin so that it can be properly loaded from within the bundle.
Check for install_name_tool. -
@Alexuds79 said in Problem when trying to use webp in the app's final executable (Qt 6.4):
The webp library is also included in the final directory, in this path:
MyApp.app/Contents/Frameworks/libwebp.7.dylibI tried copying the library manually to the imageformats directory, but that didn't work either.
Again: Qt supports it through Qt's webp image plugin, not through a webp library somewhere in your path. So when you run your app from QtCreator it must load this plugin from somewhere. When you then run macdeployqt another Qt installation must be picked up where the plugin is not available.
-
@Christian-Ehrlicher @SGaist I think I managed to solve the problem. The problem is that the webp library is not included in the Qt installation directory. I mean, by default, in the path /Users/user/Qt/6.4.2/macos/plugins/imageformats, only the following libraries are included in my case:
libqgif.dylib libqico.dylib libqjpeg.dylib libqsvg.dylib
I understand that for this reason, when macdeployqt generates the final application directory, it does not include the webp library.
However, I have been able to find much more libraries in the path /Users/user/Qt/QtDesignStudio/qt6_design_studio_reduced_version/plugins/imageformats, including the following one:
libqwebp.dylib
All I had to do is to copy libqwebp.dylib
to /Users/user/Qt/6.4.2/macos/plugins/imageformats, build the final project executable again, and it works.Thanks a lot to both of you! :))
-