Qt .qrc檔案

來源:互聯網
上載者:User

資源檔

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");


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.