Adding image files to .qrc dynamically

  • Hi ,

    Is there any way to add images to .qrc file dynamically from the program itself.
    i would like to place all my images in a particular folder and when i compile my program the newly copied images should be added automatically.


  • I think that is not possible since the .qrc file is compiled and qrc_resourcesNameFile.cpp generated. This is the fail then added to the exec.

  • Lifetime Qt Champion


    I'm not sure I am following you.

    Would you like that i.e. Qt creator to automatically append newly added images from a folder to a given qrc before building ?

  • Ok , if that is not possible i trying to read the contents of .qrc file using below approach.

    my app is supposed to run on multiple platforms , will the following code portable or is there any stanadard way of extracting required files from .qrc.

    QFile file("/home/wip/lays/images_QRC.qrc");|QIODevice::Text);

    QTextStream in(&file);
    QString line = in.readLine();
        if(line.contains("jpeg")||line.contains("png")){ // filters only images 
            qDebug()<<"line 1 "<<line;
            QStringList line1 = line.split("<file>"); //removes "         <file>"
            line = line1[1];
            qDebug()<<"line 2 "<< line1[1];
            QStringList line2 =line.split("</file>");//removes  </file>
            line = line2[0];
            qDebug()<<"line 3 "<<line;
        line = in.readLine();


  • You'll have more chance of success reading the qrc file as xml. Your code assumes that tags and text are all on one line, which may not be the case.

  • Hi,
    is there any standard way , to extract files from qrc?

  • Lifetime Qt Champion

    There are no files to extract from the qrc file.

    It's just an xml list of files on your system that rcc will transform to be compiled in your application, see the "rcc": doc

    For more information there is the "resources": documentation

    Hope it helps

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.