Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    additional file
    3
    3
    623
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Alfred Plohoy last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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();
        
        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 0
          • First post
            Last post