資源檔
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=new
QSplashScreen;
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");