Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Requirements for svg icons? Changed in Qt 5.10.1?
Forum Update on Monday, May 27th 2025

Requirements for svg icons? Changed in Qt 5.10.1?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
svgicons
12 Posts 5 Posters 12.1k 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.
  • jpnurmiJ Offline
    jpnurmiJ Offline
    jpnurmi
    wrote on last edited by
    #3

    Besides the built-in image formats, such as PNG, supported image formats are determined by the available image format plugins. The image format plugins are located in QTDIR/plugins/imageformats and must be deployed to together with your application. The SVG image format plugin is called something like libqsvg.so, libqsvg.dylib, or qsvg.dll, depending on the platform.

    http://doc.qt.io/qt-5/windows-deployment.html#qt-plugins

    Your application may also depend on one or more Qt plugins, such as the print support plugin, the JPEG image format plugin or a SQL driver plugin. Be sure to distribute any Qt plugins that you need with your application. Similar to the platform plugin, each type of plugin must be located within a specific subdirectory (such as printsupport, imageformats or sqldrivers) within your distribution directory.

    1 Reply Last reply
    3
    • M Offline
      M Offline
      markugra
      wrote on last edited by
      #4

      Thanks for your replies!

      @SGaist: I did not have QT+=svg in my pro file (neither in the current nor the previously working version), but I tried it before and now again and it does not have an effect on the error

      @jpnurmi: I am currently just trying to run the application in Qt Creator without deploying it. Just to male sure, I did check the QTDIR and the qsvg.dll is where it is supposed to be. They also got deployed correctly the previous time with windeployqt. (Although I do remember that windeployqt automatically detected Qt5SVG without me specifying it in the pro file)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        markugra
        wrote on last edited by
        #5

        So I just tried to build a minimum working example and realized that maybe the way I am implementing the icons might be part of the problem:

        I am using IconLabel{} (import QtQuick.Controls.impl 2.3), but I noticed it is not in the documentation. I got it from a Material button implementation and I used it because it provides the icon property and I assumed that it would handle different display resolutions.

        Talking about display resolutions, I just disconnected my second monitor (connected via HDMI) in order to call it a day and all of a sudden the application compiles without error and the svg icons are all displayed! This is reproducible.

        I 'll have to check if/how different resolution are handled in this application, but if someone has a clue what could cause this, I am grateful for any hints.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          markugra
          wrote on last edited by
          #6

          Ok, so after restarting I cannot seem to reproduce this error anymore.

          In terms of requirements for icons, however, I am interested in the recommended way to use them outside of a Button i.e. just as a non clickable image, but with the icon functionalities such as dpi dependent scaling or adjustable color. Here is a minimal working example of how I am using it right now with the not documented IconLabel{} that apparently requires the modules QtQuick.Controls.impl 2.3 as well as QtQuick.Templates 2.3:

          import QtQuick 2.10
          import QtQuick.Window 2.10
          import QtQuick.Controls 2.3
          import QtQuick.Controls.impl 2.3 //provides IconLabel
          import QtQuick.Templates 2.3 as T //apparently necessary to set the icon property of IconLabel
          import "."
          
          Window {
              visible: true
              width: 640
              height: 480
              title: qsTr("Hello World")
              Column{
                  IconLabel{
                      id: iconID
                      icon { source:"qrc:/someicon.svg"
                                      width: 24 ; height: 24; color: "green"
                      }
                      display: AbstractButton.IconOnly
                  }
              }
          }
          
          1 Reply Last reply
          0
          • jpnurmiJ Offline
            jpnurmiJ Offline
            jpnurmi
            wrote on last edited by jpnurmi
            #7

            IconLabel is a helper type that creates image and text elements on demand. Since you intend to always show an icon, you can use a type called IconImage directly. The original plan was to make IconImage part of Qt Quick core, next to Image and other inherited types, but somehow it got rejected as the use cases weren't presumably understood well enough. You can use IconImage from the internal namespace for now, but there's a risk that your code won't run with future Qt versions if and when the type is moved. Anyway, it would be very much appreciated if you'd let the development team know (via bugreports.qt.io) why and how you would like to use it.

            M 1 Reply Last reply
            3
            • jpnurmiJ jpnurmi

              IconLabel is a helper type that creates image and text elements on demand. Since you intend to always show an icon, you can use a type called IconImage directly. The original plan was to make IconImage part of Qt Quick core, next to Image and other inherited types, but somehow it got rejected as the use cases weren't presumably understood well enough. You can use IconImage from the internal namespace for now, but there's a risk that your code won't run with future Qt versions if and when the type is moved. Anyway, it would be very much appreciated if you'd let the development team know (via bugreports.qt.io) why and how you would like to use it.

              M Offline
              M Offline
              markugra
              wrote on last edited by
              #8

              @jpnurmi : Thanks for the information. Would I report this as a bug i.e. "IconImage not in Qt Quick core", or is there a more appropriate way? I don't see anything like feature request in the list.

              jpnurmiJ 1 Reply Last reply
              0
              • M markugra

                @jpnurmi : Thanks for the information. Would I report this as a bug i.e. "IconImage not in Qt Quick core", or is there a more appropriate way? I don't see anything like feature request in the list.

                jpnurmiJ Offline
                jpnurmiJ Offline
                jpnurmi
                wrote on last edited by
                #9

                @markugra You can choose "Suggestion" as the "Issue Type". Thanks for taking the time to report. It makes it a lot easier to justify.

                1 Reply Last reply
                2
                • M Offline
                  M Offline
                  markugra
                  wrote on last edited by markugra
                  #10

                  OK, just in case someone comes across this issue as well: Since the error I mentioned ("Unsupported image format") occurred quite frequently in the last few days I had another look. I found out that it has little to do with the usage of IconLable/IconImage, but also appears for a standard QML Image. As already suspected here, the problem were missing dependencies in the .pro file. In addition to QtSvg one also has to include QtCore, QtGui (both included by default) and the in my case missing QtXml. I.e.:

                  QT += svg xml
                  

                  fixes the problem. Why the error did not always show up I cannot say though.

                  EDIT: I'm afraid this did not fix the problem after all. The error still occurs occasionally.

                  DiracsbracketD 1 Reply Last reply
                  1
                  • M markugra

                    OK, just in case someone comes across this issue as well: Since the error I mentioned ("Unsupported image format") occurred quite frequently in the last few days I had another look. I found out that it has little to do with the usage of IconLable/IconImage, but also appears for a standard QML Image. As already suspected here, the problem were missing dependencies in the .pro file. In addition to QtSvg one also has to include QtCore, QtGui (both included by default) and the in my case missing QtXml. I.e.:

                    QT += svg xml
                    

                    fixes the problem. Why the error did not always show up I cannot say though.

                    EDIT: I'm afraid this did not fix the problem after all. The error still occurs occasionally.

                    DiracsbracketD Offline
                    DiracsbracketD Offline
                    Diracsbracket
                    wrote on last edited by Diracsbracket
                    #11

                    @markugra
                    Dito here. SVG images don't work in Qt 5.11.0 either.

                    Edit:
                    From this link:
                    https://github.com/papyros/qml-material/issues/302

                    I learned that for Android, you also need to include the <QtSvg> header in your main file, because deployment sometimes just forgets to include the svg lib. So I just added in my main.cpp: the following:

                    #ifdef Q_OS_ANDROID
                    #include <QtSvg>    //Because deployment sometimes just forgets to include this lib otherwise
                    #endif
                    

                    This did the trick in my case.

                    1 Reply Last reply
                    5
                    • K Offline
                      K Offline
                      Kenz Dale
                      wrote on last edited by
                      #12

                      Necro-threading this because this is still a problem, at least where it would work fine in macOS, but not when deployed to iOS.

                      I solved it by adding QT += svg xml to the .pro file AND #include <QtSvg> to main.cpp. I haven't looked to see which one was minimum solution. Since this was an intermittent problem (why?), I didn't want to take any chances so just shotgunned it.

                      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