在 Windows 中的 Qt4 版本中未显示 SVG 图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4318990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SVG icons not showing up in Qt4 release build in windows
提问by vls
I have a Qt4 application with SVG icons, compiled with mingw (in windows), linked to Qt shared libraries.
我有一个带有 SVG 图标的 Qt4 应用程序,用 mingw(在 Windows 中)编译,链接到 Qt 共享库。
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 not in release build.
当应用程序运行时,SVG 图标出现在 linux 的调试和发布版本中,但是在 Windows 中,SVG 图标仅在调试版本中显示,而在发布版本中不显示。
All SVG icons are listed in project.qrc
, and project.pro
has RESOURCES = project.qrc
. Application uses QtSvg4.dll (version 4.7.0).
所有 SVG 图标都列在 中project.qrc
,并且project.pro
具有RESOURCES = project.qrc
。应用程序使用 QtSvg4.dll(版本 4.7.0)。
Qt 4.7.0, Qt Creator 2.0.1, mingw/g++ 4.4.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.
解决方案更新:在应用程序目录下,创建/imageformats/目录并将qsvg4.dll放在那里而不是应用程序目录本身,或者创建一个qt.conf
具有适当路径的文件。部署插件的更多信息。
采纳答案by Chris
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.
很可能您必须包含 qt 目录中的插件。这涉及制作一个应用程序本地的 qt.conf 文件(请参阅此处:http://doc.qt.io/qt-4.8/qt-conf.html ,更具体地说是 [Paths] 部分),然后复制 c :\Qt\4.xx\plugins\imageformats*.dll 到你的发行版目录。
回答by ManuelSchneid3r
For Qt5
对于 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.
自 Qt5 以来,该框架已经高度模块化(模块列表)。您很可能缺少 svg 模块。应用程序仍然可以编译而不会抱怨。确保 SVG 模块已安装在您的系统上并已链接(使用 qmake (Howto)、cmake (Howto)或普通 make)。如果链接成功QImageReader::supportedImageFormats()将列出 SVG。
回答by ulidtko
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
!
只需将此行添加到您的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:
就我而言,Qt 是从 MSYS2 静态链接的,因此插件 DLL 甚至不存在。但是该应用程序仍然必须链接该imageformats/qsvg
插件代码。上面的 qmake 行是最简单的方法;它转换为g++
链接线段,如下所示:
g++ [...] -LC:/msys64/mingw64/qt5-static/share/qt5/plugins/imageformats \
C:/msys64/mingw64/qt5-static/share/qt5/plugins/imageformats/libqsvg.a [...]
回答by undy
For my (Qt 4.6.3) application, I solved this by putting the plug-in dll (qsvgicon4.dll) in a directory called iconengineswithin the application directory.
对于我的 (Qt 4.6.3) 应用程序,我通过将插件 dll (qsvgicon4.dll) 放在应用程序目录中名为iconengines的目录中解决了这个问题。
Tried other solutions - such as deploying plugin to directory (within app directory) named imageformatswith and without an appropriate qt.conf, but no joy.
尝试了其他解决方案 - 例如将插件部署到名为imageformats 的目录(在 app 目录中),有和没有适当的 qt.conf,但没有乐趣。
Note: I previously ran the application with Qt 4.7.0 dlls and had no problems on the same Win7 target machine.
注意:我以前使用 Qt 4.7.0 dll 运行该应用程序,并且在同一台 Win7 目标机器上没有问题。
回答by OliJG
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://lists.trolltech.com/qt-interest/2008-10/msg00655.html
http://www.qtcentre.org/archive/index.php/t-9036.html
http://www.qtcentre.org/archive/index.php/t-9036.html
In particular, make sure that the SVG plugin is getting loaded with:
特别是,确保 SVG 插件加载了:
QImageReader::supportedImageFromats()
QImageReader::supportedImageFromats()
回答by adler
It still seem to be a problem with Qt5.1 in Windows, here how I solved it for cmake users:
Windows 中的 Qt5.1 似乎仍然存在问题,这里我是如何为 cmake 用户解决的:
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:
它的手动方式,不漂亮但有效。QTBinBase 我得到了另一个肮脏的把戏:
get_target_property(QtCore_location Qt5::Core LOCATION)
get_filename_component(QtBinBase ${QtCore_location} PATH)
回答by c0de
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.
如果添加 Qt4Svg.dll 并且 imageformats/qsvg4.dll 不起作用,请确保 Qt4Xml.dll 也包含在标准核心、gui 和 svg DLL 中。
This is how I solved this for me.
这就是我为我解决的方法。
Short: to render svg images you need to include the xml DLL aswell
简短:要呈现 svg 图像,您还需要包含 xml DLL