读书人

Qt .qrc资料

发布时间: 2012-12-31 11:57:52 作者: rapoo

Qt .qrc文件

资源文件

The Qt resource system is a platform-independent mechanism for storing binary files in the application's executable. This is useful if your application always needs a certain set of files (icons, translation files, etc.) and you don't want to run the risk of losing the files.

这句话讲的非常明确,Qt资源文件是一个与平台无关的方法讲二进制文件保存到可执行程序内。对于你的应用程序常常需要一些文件(比如图像文件,译文等),并且你不希望这些文件有丢失的危险,使用Qt资源文件是非常有用的。


1、将图像资源等都包含在一个文件夹中,如images,

在QtCreater中创建qrc文件的方法:

添加新文件—Qt—Qt资源文件

在资源文件中添加前缀、文件等


2、在工程文件*.pro中添加行:

RESOURCES += application.qrc


3、在main函数中强制初始化资源Q_INIT_RESOURCE(application);如:


int main(int argc, char *argv[])

{

Q_INIT_RESOURCE(application);

//资源定义宏

...


}

4、使用

QSplashScreen *splash=newQSplashScreen;

    splash->setPixmap(QPixmap(QString(":/images/splash.jpg")).scaled(deskRect.size(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
splash->show();



在windows下的问题:png图片打不开,jpg和bmp都可以

解决办法:在引用的时候去掉:后的“/”,

    top.load(":images/jiaSu.png");





读书人网 >其他相关

热点推荐