Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem when trying to use webp in the app's final executable (Qt 6.4)
QtWS25 Last Chance

Problem when trying to use webp in the app's final executable (Qt 6.4)

Scheduled Pinned Locked Moved Solved General and Desktop
webpimageformatscmakeqt 6.4.2
9 Posts 4 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alexuds79
    wrote on last edited by
    #1

    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 EhrlicherC 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @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.dylib

      I 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.

      A Offline
      A Offline
      Alexuds79
      wrote on last edited by
      #8

      @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! :))

      1 Reply Last reply
      0
      • A Alexuds79

        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 EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @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.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        A 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @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.

          A Offline
          A Offline
          Alexuds79
          wrote on last edited by
          #3

          @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
          
          Christian EhrlicherC 1 Reply Last reply
          0
          • A Alexuds79

            @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
            
            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @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.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            A 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              @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.

              A Offline
              A Offline
              Alexuds79
              wrote on last edited by
              #5

              @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.

              SGaistS Christian EhrlicherC 2 Replies Last reply
              0
              • A Alexuds79

                @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.

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by SGaist
                #6

                @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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • A Alexuds79

                  @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.

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @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.dylib

                  I 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.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  A 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @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.dylib

                    I 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.

                    A Offline
                    A Offline
                    Alexuds79
                    wrote on last edited by
                    #8

                    @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! :))

                    1 Reply Last reply
                    0
                    • A Alexuds79 has marked this topic as solved on
                    • T Offline
                      T Offline
                      Tim Angus
                      wrote on last edited by Tim Angus
                      #9

                      Probably a better solution is to select the Qt Image Formats module in MaintenanceTool (the online installer). It isn't installed by default and won't include webp support.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved