Qt 4.8.6 静态编译库 无法显示ico的图片格式

king1076 2014-08-08 05:55:20
Qt版本是4.8.6 vs编译的静态库 无法正常显示ico格式的图片。
但是动态库 显示ico没有问题。有遇到这种情况吗。
...全文
425 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jamesguo37 2014-08-15
  • 打赏
  • 举报
回复
How to Create Qt Plugins Qt provides two APIs for creating plugins: A higher-level API for writing extensions to Qt itself: custom database drivers, image formats, text codecs, custom styles, etc. A lower-level API for extending Qt applications. For example, if you want to write a custom QStyle subclass and have Qt applications load it dynamically, you would use the higher-level API. Since the higher-level API is built on top of the lower-level API, some issues are common to both. If you want to provide plugins for use with Qt Designer, see the QtDesigner module documentation. Topics: The Higher-Level API: Writing Qt Extensions The Lower-Level API: Extending Qt Applications Locating Plugins Static Plugins The Higher-Level API: Writing Qt Extensions Writing a plugin that extends Qt itself is achieved by subclassing the appropriate plugin base class, implementing a few functions, and adding a macro. There are several plugin base classes. Derived plugins are stored by default in sub-directories of the standard plugin directory. Qt will not find plugins if they are not stored in the right directory. Base Class Directory Name Key Case Sensitivity QAccessibleBridgePlugin accessiblebridge Case Sensitive QAccessiblePlugin accessible Case Sensitive QDecorationPlugin decorations Case Insensitive QFontEnginePlugin fontengines Case Insensitive QIconEnginePlugin iconengines Case Insensitive QImageIOPlugin imageformats Case Sensitive QInputContextPlugin inputmethods Case Sensitive QKbdDriverPlugin kbddrivers Case Insensitive QMouseDriverPlugin mousedrivers Case Insensitive QScreenDriverPlugin gfxdrivers Case Insensitive QScriptExtensionPlugin script Case Sensitive QSqlDriverPlugin sqldrivers Case Sensitive QStylePlugin styles Case Insensitive QTextCodecPlugin codecs Case Sensitive Suppose that you have a new style class called MyStyle that you want to make available as a plugin. The required code is straightforward, here is the class definition (mystyleplugin.h):

 class MyStylePlugin : public QStylePlugin
 {
 public:
     QStringList keys() const;
     QStyle *create(const QString &key);
 };
Ensure that the class implementation is located in a .cpp file (including the class definition):

 #include "mystyleplugin.h"

 QStringList MyStylePlugin::keys() const
 {
     return QStringList() << "MyStyle";
 }

 QStyle *MyStylePlugin::create(const QString &key)
 {
     if (key.toLower() == "mystyle")
         return new MyStyle;
     return 0;
 }
[/code=c]
 Q_EXPORT_PLUGIN2(pnp_mystyleplugin, MyStylePlugin)
(Note that QStylePlugin is case insensitive, and the lower-case version of the key is used in our create() implementation; most other plugins are case sensitive.)

For database drivers, image formats, text codecs, and most other plugin types, no explicit object creation is required. Qt will find and create them as required. Styles are an exception, since you might want to set a style explicitly in code. To apply a style, use code like this:

 QApplication::setStyle(QStyleFactory::create("MyStyle"));
Some plugin classes require additional functions to be implemented. See the class documentation for details of the virtual functions that must be reimplemented for each type of plugin.

The Style Plugin Example shows how to implement a plugin that extends the QStylePlugin base class.

The Lower-Level API: Extending Qt Applications

Not only Qt itself but also Qt application can be extended through plugins. This requires the application to detect and load plugins using QPluginLoader. In that context, plugins may provide arbitrary functionality and are not limited to database drivers, image formats, text codecs, styles, and the other types of plugin that extend Qt's functionality.

Making an application extensible through plugins involves the following steps:

Define a set of interfaces (classes with only pure virtual functions) used to talk to the plugins.
Use the Q_DECLARE_INTERFACE() macro to tell Qt's meta-object system about the interface.
Use QPluginLoader in the application to load the plugins.
Use qobject_cast() to test whether a plugin implements a given interface.
Writing a plugin involves these steps:

Declare a plugin class that inherits from QObject and from the interfaces that the plugin wants to provide.
Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces.
Export the plugin using the Q_EXPORT_PLUGIN2() macro.
Build the plugin using a suitable .pro file.
For example, here's the definition of an interface class:
[code=c]
 class FilterInterface
 {
 public:
     virtual ~FilterInterface() {}

     virtual QStringList filters() const = 0;
     virtual QImage filterImage(const QString &filter, const QImage &image,
                                QWidget *parent) = 0;
 };
[/code=c]
Here's the definition of a plugin class that implements that interface:
[code=c]
 #include <QObject>
 #include <QStringList>
 #include <QImage>

 #include <plugandpaint/interfaces.h>

 class ExtraFiltersPlugin : public QObject, public FilterInterface
 {
     Q_OBJECT
     Q_INTERFACES(FilterInterface)

 public:
     QStringList filters() const;
     QImage filterImage(const QString &filter, const QImage &image,
                        QWidget *parent);
 };
jamesguo37 2014-08-15
  • 打赏
  • 举报
回复
How to Create Qt Plugins Qt provides two APIs for creating plugins: A higher-level API for writing extensions to Qt itself: custom database drivers, image formats, text codecs, custom styles, etc. A lower-level API for extending Qt applications. For example, if you want to write a custom QStyle subclass and have Qt applications load it dynamically, you would use the higher-level API. Since the higher-level API is built on top of the lower-level API, some issues are common to both. If you want to provide plugins for use with Qt Designer, see the QtDesigner module documentation. Topics: The Higher-Level API: Writing Qt Extensions The Lower-Level API: Extending Qt Applications Locating Plugins Static Plugins The Higher-Level API: Writing Qt Extensions Writing a plugin that extends Qt itself is achieved by subclassing the appropriate plugin base class, implementing a few functions, and adding a macro. There are several plugin base classes. Derived plugins are stored by default in sub-directories of the standard plugin directory. Qt will not find plugins if they are not stored in the right directory. Base Class Directory Name Key Case Sensitivity QAccessibleBridgePlugin accessiblebridge Case Sensitive QAccessiblePlugin accessible Case Sensitive QDecorationPlugin decorations Case Insensitive QFontEnginePlugin fontengines Case Insensitive QIconEnginePlugin iconengines Case Insensitive QImageIOPlugin imageformats Case Sensitive QInputContextPlugin inputmethods Case Sensitive QKbdDriverPlugin kbddrivers Case Insensitive QMouseDriverPlugin mousedrivers Case Insensitive QScreenDriverPlugin gfxdrivers Case Insensitive QScriptExtensionPlugin script Case Sensitive QSqlDriverPlugin sqldrivers Case Sensitive QStylePlugin styles Case Insensitive QTextCodecPlugin codecs Case Sensitive Suppose that you have a new style class called MyStyle that you want to make available as a plugin. The required code is straightforward, here is the class definition (mystyleplugin.h): class MyStylePlugin : public QStylePlugin { public: QStringList keys() const; QStyle *create(const QString &key); }; Ensure that the class implementation is located in a .cpp file (including the class definition): #include "mystyleplugin.h" QStringList MyStylePlugin::keys() const { return QStringList() << "MyStyle"; } QStyle *MyStylePlugin::create(const QString &key) { if (key.toLower() == "mystyle") return new MyStyle; return 0; } Q_EXPORT_PLUGIN2(pnp_mystyleplugin, MyStylePlugin) (Note that QStylePlugin is case insensitive, and the lower-case version of the key is used in our create() implementation; most other plugins are case sensitive.) For database drivers, image formats, text codecs, and most other plugin types, no explicit object creation is required. Qt will find and create them as required. Styles are an exception, since you might want to set a style explicitly in code. To apply a style, use code like this: QApplication::setStyle(QStyleFactory::create("MyStyle")); Some plugin classes require additional functions to be implemented. See the class documentation for details of the virtual functions that must be reimplemented for each type of plugin. The Style Plugin Example shows how to implement a plugin that extends the QStylePlugin base class. The Lower-Level API: Extending Qt Applications Not only Qt itself but also Qt application can be extended through plugins. This requires the application to detect and load plugins using QPluginLoader. In that context, plugins may provide arbitrary functionality and are not limited to database drivers, image formats, text codecs, styles, and the other types of plugin that extend Qt's functionality. Making an application extensible through plugins involves the following steps: Define a set of interfaces (classes with only pure virtual functions) used to talk to the plugins. Use the Q_DECLARE_INTERFACE() macro to tell Qt's meta-object system about the interface. Use QPluginLoader in the application to load the plugins. Use qobject_cast() to test whether a plugin implements a given interface. Writing a plugin involves these steps: Declare a plugin class that inherits from QObject and from the interfaces that the plugin wants to provide. Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces. Export the plugin using the Q_EXPORT_PLUGIN2() macro. Build the plugin using a suitable .pro file. For example, here's the definition of an interface class: class FilterInterface { public: virtual ~FilterInterface() {} virtual QStringList filters() const = 0; virtual QImage filterImage(const QString &filter, const QImage &image, QWidget *parent) = 0; }; Here's the definition of a plugin class that implements that interface: #include <QObject> #include <QStringList> #include <QImage> #include <plugandpaint/interfaces.h> class ExtraFiltersPlugin : public QObject, public FilterInterface { Q_OBJECT Q_INTERFACES(FilterInterface) public: QStringList filters() const; QImage filterImage(const QString &filter, const QImage &image, QWidget *parent); };
yjzl1911 2014-08-13
  • 打赏
  • 举报
回复
引用 3 楼 foruok 的回复:
dext 说得对。 ./configure --help 好好看一下。
今天灵光一闪 将图片换成 png 格式的,居然可以了。configure 之前也专研了一下,在configure的时候已经添加了下面配置: -svg -qt-libjpeg -qt-libmng -qt-libpng 但为啥图片改成 png 格式的原因我想是因为下面这个: 这是configure执行时的打印: Building on: qws/linux-x86-g++ Building for: qws/linux-arm-g++ Architecture: arm Host architecture: i386 Build .................. libs translations Configuration .......... cross_compile release embedded stl neon exceptions_off minimal-config small-config medium-config large-config full-config no-pkg-config qt3support accessibility shared embedded reduce_exports ipv6 clock-gettime clock-monotonic mremap getaddrinfo ipv6ifname getifaddrs inotify png system-tiff freetype zlib nis alsa concurrent multimedia svg script scripttools declarative release Debug .................. no Qt 3 compatibility ..... yes QtDBus module .......... no QtConcurrent code ...... yes QtGui module ........... yes QtScript module ........ yes QtScriptTools module ... yes QtXmlPatterns module ... no Phonon module .......... no Multimedia module ...... auto SVG module ............. yes WebKit module .......... no JavaScriptCore JIT ..... To be decided by JavaScriptCore Declarative module ..... yes Declarative debugging ...yes Support for S60 ........ no Symbian DEF files ...... no STL support ............ yes PCH support ............ no MMX/3DNOW/SSE/SSE2/SSE3. no/no/no/no/no SSSE3/SSE4.1/SSE4.2..... no/no/no AVX..................... no iWMMXt support ......... no NEON support ........... yes IPv6 support ........... yes IPv6 ifname support .... yes getaddrinfo support .... yes getifaddrs support ..... yes Accessibility .......... yes NIS support ............ yes CUPS support ........... no Iconv support .......... no Glib support ........... no GStreamer support ...... no PulseAudio support ..... no Large File support ..... no GIF support ............ plugin TIFF support ........... plugin (system) JPEG support ........... plugin (qt) PNG support ............ yes (qt) MNG support ............ plugin (qt) 可以看到 PNG support 对应的是yes;而 JPEG 对应的是 . plugin (qt);我不太明白的是 . plugin (qt) 不是表示以插件的形式支持吗? 为何没能成功显示 jpg格式的图片呢?
foruok 2014-08-13
  • 打赏
  • 举报
回复
dext 说得对。 ./configure --help 好好看一下。
yjzl1911 2014-08-13
  • 打赏
  • 举报
回复
引用 7 楼 king1076 的回复:
[quote=引用 4 楼 yjzl1911 的回复:] [quote=引用 3 楼 foruok 的回复:] dext 说得对。 ./configure --help 好好看一下。 哪一个 是ico的插件呢。。。
貌似真没看到过 哪个配置项是跟ico格式图片相关的。你其实也可以将ico格式的图片转成png 或 jpg格式试试看是不是跟图片格式相关的。
king1076 2014-08-13
  • 打赏
  • 举报
回复
引用 4 楼 yjzl1911 的回复:
[quote=引用 3 楼 foruok 的回复:] dext 说得对。 ./configure --help 好好看一下。
今天灵光一闪 将图片换成 png 格式的,居然可以了。configure 之前也专研了一下,在configure的时候已经添加了下面配置: -svg -qt-libjpeg -qt-libmng -qt-libpng 但为啥图片改成 png 格式的原因我想是因为下面这个: 这是configure执行时的打印: Building on: qws/linux-x86-g++ Building for: qws/linux-arm-g++ Architecture: arm Host architecture: i386 Build .................. libs translations Configuration .......... cross_compile release embedded stl neon exceptions_off minimal-config small-config medium-config large-config full-config no-pkg-config qt3support accessibility shared embedded reduce_exports ipv6 clock-gettime clock-monotonic mremap getaddrinfo ipv6ifname getifaddrs inotify png system-tiff freetype zlib nis alsa concurrent multimedia svg script scripttools declarative release Debug .................. no Qt 3 compatibility ..... yes QtDBus module .......... no QtConcurrent code ...... yes QtGui module ........... yes QtScript module ........ yes QtScriptTools module ... yes QtXmlPatterns module ... no Phonon module .......... no Multimedia module ...... auto SVG module ............. yes WebKit module .......... no JavaScriptCore JIT ..... To be decided by JavaScriptCore Declarative module ..... yes Declarative debugging ...yes Support for S60 ........ no Symbian DEF files ...... no STL support ............ yes PCH support ............ no MMX/3DNOW/SSE/SSE2/SSE3. no/no/no/no/no SSSE3/SSE4.1/SSE4.2..... no/no/no AVX..................... no iWMMXt support ......... no NEON support ........... yes IPv6 support ........... yes IPv6 ifname support .... yes getaddrinfo support .... yes getifaddrs support ..... yes Accessibility .......... yes NIS support ............ yes CUPS support ........... no Iconv support .......... no Glib support ........... no GStreamer support ...... no PulseAudio support ..... no Large File support ..... no GIF support ............ plugin TIFF support ........... plugin (system) JPEG support ........... plugin (qt) PNG support ............ yes (qt) MNG support ............ plugin (qt) 可以看到 PNG support 对应的是yes;而 JPEG 对应的是 . plugin (qt);我不太明白的是 . plugin (qt) 不是表示以插件的形式支持吗? 为何没能成功显示 jpg格式的图片呢?[/quote] 哪一个 是ico的插件呢。。。
king1076 2014-08-13
  • 打赏
  • 举报
回复
引用 3 楼 foruok 的回复:
dext 说得对。 ./configure --help 好好看一下。
目前出现的问题是 除了ico的格式,其他类型的图片都能显示。
king1076 2014-08-13
  • 打赏
  • 举报
回复
引用 3 楼 foruok 的回复:
dext 说得对。 ./configure --help 好好看一下。
引用 3 楼 foruok 的回复:
dext 说得对。 ./configure --help 好好看一下。
我看过了,但是没有ico的那个选项,tiff,png之类的我都,添加到编译条件里,但是结果还是不可以。
yjzl1911 2014-08-12
  • 打赏
  • 举报
回复
引用 1 楼 dext 的回复:
ICO 的支持 是靠插件 的。你在静态编译的时候 可以选择,把插件 也静态编译了。或者 静态加载插件。
搭个顺风车问下版主类似的问题: 最近在搞嵌入式版本的qt,原来使用厂家SDK中的qt库程序可以正常显示 icon 的图标(为一jpg格式的图片), 现在换了我自己编译的qt库,发现无法显示 icon的图标了。 请教下版主,这个原因有可能是啥? 我在编译qt的时候并没有指定 -static 参数,编出来的应该是动态库。
dext 2014-08-08
  • 打赏
  • 举报
回复
ICO 的支持 是靠插件 的。你在静态编译的时候 可以选择,把插件 也静态编译了。或者 静态加载插件。

16,235

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧