如何从共享库初始化 Qt 资源? [英] How to initialize Qt resources from a shared library?

查看:129
本文介绍了如何从共享库初始化 Qt 资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何初始化在 Red Hat Enterprise Linux 5.2 下的共享库中声明和使用的 Qt 资源.

I can not figure out how to initialize Qt resources declared in and used by a shared library under Red Hat Enterprise Linux 5.2.

我在我的共享库中添加了一个 Qt 资源文件,添加了一个名为resource"的前缀,并添加了一个文件files/styleSheet.xsl".资源文件名为resources.qrc".QFile::exists 返回 false?

I added a Qt resource file to my shared library, added a prefix named "resource", and added a file "files/styleSheet.xsl". The resource file is named "resources.qrc". QFile::exists returns false?

MySharedLib::MySharedLib()
{

   // I think Q_INIT_RESOURCE basically expands to this:
   // The resource file is named "resources.qrc"
   extern int qInitResources_resources();
   qInitResources_resources(); 

      QString resourcePath = ":/resource/files/styleSheet.xsl";
      if( false == QFile::exists(resourcePath))
      {
         printf("*** Error - Resource path not found : \"%s\"\n",   resourcePath.toLatin1().data());
      }

}

预先感谢您提供任何提示或建议,

Thanks in advance for any tips or suggestions,

推荐答案

问题是在 Linux 下,您的共享库和应用程序中不能有同名的 Qt 资源文件 (*.qrc).这在 Windows 下不是问题,但在 Linux 下它只会加载同名资源文件之一.我在我的应用程序和共享库文件中都将资源文件命名为resources.qrc".我重命名为resourcesmylib.qrc"和resourcesmyapp.qrc",一切都很好.我不需要向我的库添加调用 Q_INIT_RESOURCES 或调用 qInitResources_resources*.

The problem is that under Linux, you can not have identically named Qt resource files (*.qrc) in both your shared library and application. This is not a problem under Windows but under Linux it will only load one of the identically named resource files. I had named resource files in both my application and shared library files "resources.qrc". I renamed to "resourcesmylib.qrc" and "resourcesmyapp.qrc" and all was good. I did not need to add a call Q_INIT_RESOURCES to my library or call qInitResources_resources*.

解决方案

  • 使用唯一的 Qt 资源文件名您在 Linux 下的库和应用程序.

感谢 Qt-Interest 邮件列表中的 Jaco N..谢谢雅科!

Credit goes to Jaco N. on the Qt-Interest mailing list. Thank you Jaco!

这篇关于如何从共享库初始化 Qt 资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆