开发者

SVG icons not showing up in Qt4 release build in windows

I have a Qt4 application with SVG icons, compiled with mingw (in windows), linked to Qt shared libraries.

When application is run, SVG icons show up in debug and release builds in linux, however in windows SVG icons show up only in debug build but 开发者_如何学Cnot in release build.

All SVG icons are listed in project.qrc, and project.pro has RESOURCES = project.qrc. Application uses QtSvg4.dll (version 4.7.0).

Qt 4.7.0, Qt Creator 2.0.1, mingw/g++ 4.4.0.

Solution update: In application directory, create /imageformats/ directory and put qsvg4.dll there instead of application directory itself, or create a qt.conf file with appropriate path. More information in deploying plugins.


Most likely you will have to include the plugins from your qt dir. This involves making a qt.conf file that is local to your app (see here: http://doc.qt.io/qt-4.8/qt-conf.html , more specifically the [Paths] section), and copy c:\Qt\4.x.x\plugins\imageformats*.dll to your distributable's directory.


for Qt 5.14 add a line to the .pro file

QT       += svg


For Qt5

Since Qt5 the framework has been heavily modularized (List of Modules). Most likely you are missing the svg module. The application will still compile without complaining. Make sure the SVG module is installed on your system and linked (with qmake (Howto), cmake (Howto) or plain make). If it was linked successfully QImageReader::supportedImageFormats() will list SVG.


For my (Qt 4.6.3) application, I solved this by putting the plug-in dll (qsvgicon4.dll) in a directory called iconengines within the application directory.

Tried other solutions - such as deploying plugin to directory (within app directory) named imageformats with and without an appropriate qt.conf, but no joy.

Note: I previously ran the application with Qt 4.7.0 dlls and had no problems on the same Win7 target machine.


You guessed it: here's yet another way to avoid reading the docs, but instead to rely on cheap advice from the internet.

Just add this line to your app.pro!

QTPLUGINS += qsvg

In my case, Qt is static linked from MSYS2, so plugin DLLs don't even exist. But the app still has to link in that imageformats/qsvg plugin code. The qmake line above is about the easiest way to do it; it translates to the g++ link line segment like this:

g++ [...] -LC:/msys64/mingw64/qt5-static/share/qt5/plugins/imageformats \
          C:/msys64/mingw64/qt5-static/share/qt5/plugins/imageformats/libqsvg.a [...]


Based on what you've said, you're doing all that's needed for it to work, so a proper answer is likely to require some more information. See if these links are of any use to you:

http://lists.trolltech.com/qt-interest/2008-10/msg00655.html

http://www.qtcentre.org/archive/index.php/t-9036.html

In particular, make sure that the SVG plugin is getting loaded with:

QImageReader::supportedImageFromats()


It still seem to be a problem with Qt5.1 in Windows, here how I solved it for cmake users:

Find_File(qtsvg NAMES "Qt5Svg.dll" PATHS ${QTBinBase}/.. PATH_SUFFIXES "bin" )
Find_File(qtxml NAMES Qt5Xml.dll PATHS ${QTBinBase}/.. PATH_SUFFIXES "bin" )
Find_File(qsvg NAMES "qsvg.dll" PATHS ${QTBinBase}/.. PATH_SUFFIXES "plugins/imageformats" )
Find_File(qsvgicon NAMES "qsvgicon.dll" PATHS ${QTBinBase}/.. PATH_SUFFIXES "plugins/iconengines" )

install(FILES ${qtsvg} ${qtxml} DESTINATION bin)
install(FILES ${qsvg} DESTINATION bin/plugins/imageformats)
install(FILES ${qsvgicon} DESTINATION bin/plugins/iconengines)

Its the manual way, not beautiful but works. QTBinBase I got with another dirty trick:

get_target_property(QtCore_location Qt5::Core LOCATION)
get_filename_component(QtBinBase ${QtCore_location} PATH)


If adding the Qt4Svg.dll and the imageformats/qsvg4.dll doesn't work, make sure the Qt4Xml.dll is also included along the standard core, gui and svg DLLs.

This is how I solved this for me.

Short: to render svg images you need to include the xml DLL aswell

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜