如何从共享库初始化Qt资源?

Ed *_*ain 9 resources qt shared-libraries

我无法弄清楚如何初始化Red Hat Enterprise Linux 5.2下共享库中声明和使用的Qt资源.

我在我的共享库中添加了一个Qt资源文件,添加了一个名为"resource"的前缀,并添加了一个文件"files/styleSheet.xsl".资源文件名为"resources.qrc".QFile :: exists返回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());
      }

}
Run Code Online (Sandbox Code Playgroud)

提前感谢任何提示或建议,

Ed *_*ain 11

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

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

感谢在Qt-Interest邮件列表上的Jaco N. 谢谢Jaco!