16,201
社区成员
发帖
与我相关
我的任务
分享
只能给一个大大的赞
[quote=引用 14 楼 sugar13 的回复:]
注册函数的名字是跟资源文件的名字有关的,资源叫“temp.qrc”,那么注册函数的名字就是qInitResources_temp。调用的时候会找不到函数声明,因此需要自己手动声明一下再调用:
int qInitResources_temp();
qInitResources_temp();
<fieldset><legend class="font_bold">引用 14 楼 sugar13 的回复:</legend><blockquote>注册函数的名字是跟资源文件的名字有关的,资源叫“temp.qrc”,那么注册函数的名字就是qInitResources_temp。调用的时候会找不到函数声明,因此需要自己手动声明一下再调用:<br /> <br /> <pre class="brush: c"><br /> int qInitResources_temp();<br /> qInitResources_temp();<br /> </pre></blockquote></fieldset><br /> 非常感谢!!!加上这两句就成了!!!<img src="https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/83.gif" alt="" />虽然原理不太懂~<img src="https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/13.gif" alt="" /><br /> 另:初始化一次就可以吧,用个static变量?
注册函数的名字是跟资源文件的名字有关的,资源叫“temp.qrc”,那么注册函数的名字就是qInitResources_temp。调用的时候会找不到函数声明,因此需要自己手动声明一下再调用:
int qInitResources_temp();
qInitResources_temp();
file.errorString(): No such file or directory
另:大家试过吗?在lib库里加入资源,库函数访问他。希望我们理解的一样!
谁有例子麻烦发个:1328512592@qq.com,谢谢了!
int qInitResources_temp();
qInitResources_temp();
你的lib库是静态库还是动态库?这个库是静态链接到qt还是动态链接到qt?qfile的调用发生在可执行文件中还是在库中?
我试过在动态库中的代码加载动态库中的资源,是没有问题的,只不过我用的是qicon加载图片,没有用qfile试过。
资源原文:
0 1
1 0
qrc_temp.cpp里部分内容:
static const unsigned char qt_resource_data[] = {
// E:/qt_cs/nist_3_2/nist/templates/template2
0x0,0x0,0x0,0x8,
0x30,
0x20,0x31,0xa,0x31,0x20,0x30,0xa,
};
static const unsigned char qt_resource_name[] = {
// templates
0x0,0x9,
0x4,0x72,0x7f,0x43,
0x0,0x74,
0x0,0x65,0x0,0x6d,0x0,0x70,0x0,0x6c,0x0,0x61,0x0,0x74,0x0,0x65,0x0,0x73,
// template2
0x0,0x9,
0x4,0x72,0x7f,0x2,
0x0,0x74,
0x0,0x65,0x0,0x6d,0x0,0x70,0x0,0x6c,0x0,0x61,0x0,0x74,0x0,0x65,0x0,0x32,
};
static const unsigned char qt_resource_struct[] = {
// :
0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x1,
// :/templates
0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x2,
// :/templates/template2
0x0,0x0,0x0,0x18,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,
};
cpp是自动生成的,错了也不知道为什么哦
static const unsigned char qt_resource_data[] = {
// E:/qt_cs/nist_3_2/nist/templates/template2
0x0,0x0,0x0,0x8,
0x30,
0x20,0x31,0xa,0x31,0x20,0x30,0xa,
};
static const unsigned char qt_resource_name[] = {
// templates
0x0,0x9,
0x4,0x72,0x7f,0x43,
0x0,0x74,
0x0,0x65,0x0,0x6d,0x0,0x70,0x0,0x6c,0x0,0x61,0x0,0x74,0x0,0x65,0x0,0x73,
// template2
0x0,0x9,
0x4,0x72,0x7f,0x2,
0x0,0x74,
0x0,0x65,0x0,0x6d,0x0,0x70,0x0,0x6c,0x0,0x61,0x0,0x74,0x0,0x65,0x0,0x32,
};
static const unsigned char qt_resource_struct[] = {
// :
0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x1,
// :/templates
0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x2,
// :/templates/template2
0x0,0x0,0x0,0x18,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,
};
[quote=引用 1 楼 dcmilan 的回复:]
你在资源编辑器里添加文件后
重新编译,让资源二进制化
生成对应的qrc_temp.cpp
你看这个文件有没有正确生成
你在资源编辑器里添加文件后
重新编译,让资源二进制化
生成对应的qrc_temp.cpp
你看这个文件有没有正确生成