Requirements for svg icons? Changed in Qt 5.10.1?

  • Hi there,

    Since last week Friday my QML application does not display my svg icons anymore, but instead outputs the following error:

    QML IconImage: Error decoding: qrc:/myfile.svg: Unsupported image format

    Long story short I noticed that it does work when I replace the QGuiApplication in the main.cpp with QApplication (and accordingly add QT+= widgets in the pro file).
    Does someone know what the requirements for svg icons are?

    What I cannot explain is why it worked before. I did confirm an update prompt from Qt on Friday, but I believe this just concerned Qt Creator (now based on Qt 5.10.1), since the Qt version I have in my QTDIR is still only 5.10.0. On the other hand the source code with which I created a deploy-able executable last week, now generates the error message above while the executable (in one folder with its dependencies) works fine.

    Thanks in advance for any tips.

  • Lifetime Qt Champion


    Might be a silly question but: did you already had QT += svg in your .pro file ?

  • 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.dylib, or qsvg.dll, depending on the platform.

    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.

  • 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)

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

  • 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")
                id: iconID
                icon { source:"qrc:/someicon.svg"
                                width: 24 ; height: 24; color: "green"
                display: AbstractButton.IconOnly

  • 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 why and how you would like to use it.

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

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

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.