要载入此目录下的 img.rcc 压缩资源文件。
在pro文件中加入:
android{
langs.files += assets/res/img.rcc #要载入的文件位置
langs.path = /assets/res #载入后的文件在apk包中的位置
INSTALLS += langs
}
生成的apk包:
载入和使用资源文件:
#include <QApplication>
#include <QDebug>
#include <QResource>
#include <QHBoxLayout>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qInfo()<<"载入文件"<<QResource::registerResource("assets:/res/img.rcc");
QWidget w;
auto hb = new QHBoxLayout(&w);
auto label = new QLabel;
label->setPixmap(QPixmap(":主页.png"));
hb->addWidget(label);
w.show();
return a.exec();
}
成功载入。
吐槽一下,小公司啥都要干,本人刚来是做windows qt 开发的,现在一个人负责windows、Mac、linux、centos的qt开发,连安卓开发都要开始搞了...
另外,安卓的qt环境搭建可参考:
【Android FFMPEG 开发】博客资源_2020_02_20_1https://download.csdn.net/download/han1202012/12173019