How can I add some (not program) files to release?



  • In my program i need to show some articles to user.
    These articles are stored in some *.txt files.
    When I build program, files are not copied to release directory.
    Why.


  • Qt Champions 2016

    Hi and welcome

    If you just put some text files in your project folder and load them from there,
    the tool has no way of knowing you want them
    included as they are not really part of the project.

    You could add a Resource file and put the text files there. It would then be compiled into your program and
    you can load from the internal resource. that way they would always be there.
    To load from resource one uses the ":" syntax.
    After adding the text file to "Resources" , you can right click it to get path.

    Resource common ( ":/phrases/Resources/Phrases/Common.xml" );
    
    QFile commonFile ( common.absoluteFilePath() );
    
    if ( !commonFile.open ( QIODevice::ReadOnly | QIODevice::Text ) )
    {
        qDebug() << "Unable to open file: " << commonFile.fileName() << " besause of error " << commonFile.errorString() << endl;
        return;
    }
    
    QTextStream in(&commonFile);
    QString content = in.readAll();
    

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    @mrjj 's technique is a very good suggestion.

    If you really want your files outside of your binary for any reason, you either need to add a build step to do the copy in Qt Creator or use QMAKE_POST_LINK to setup the copy commands.


Log in to reply
 

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