Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I get a text file to copy into a build?
QtWS25 Last Chance

How do I get a text file to copy into a build?

Scheduled Pinned Locked Moved General and Desktop
15 Posts 3 Posters 15.7k Views
  • 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.
  • D Offline
    D Offline
    doozii
    wrote on 11 Mar 2014, 18:08 last edited by
    #1

    Ive added a text file to my Qt Project using Add New > General > Text File. I want that text file to get copied to the output directory when I build the project so I can quit having to manually copy after the build. I can't, for the life of me, figure out how to do this "seemingly" simple task.

    When I added the text file to the project, I saw that QT Creator added a

    OTHER_FILES += \
    MyFile.txt
    (both the above are on separate lines)
    to the .pro file but I see no other way to indicate that the file should get copied with the build. I'm not looking to compile the text file into the executable. Instead, I want that file to be writable outside of the program so I can make changes and then the program will read it in at runtime.

    Would love any help I can get. Thanks in advance.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      doozii
      wrote on 11 Mar 2014, 21:15 last edited by
      #2

      I thought the QT Resource System compiled the files into the executable? If that is the case, then no. I simply want he text file to get copied into the build folder when I build. Thanks

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 11 Mar 2014, 21:23 last edited by
        #3

        Hi,

        What OS are you building on ?

        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
        0
        • D Offline
          D Offline
          doozii
          wrote on 12 Mar 2014, 03:00 last edited by
          #4

          Windows 7

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on 12 Mar 2014, 03:34 last edited by
            #5

            If you are using QtCreator then you can add one more build step on the "Projects" tab.
            This step will be written into .pro.user file and will be OS specific.

            If you are going to build your project manually by run qmake and make then you may need to run make install after successful build.
            "Take a look here":http://stackoverflow.com/questions/7795397/copy-a-file-to-the-build-directory-after-compiling-project-with-qt

            1 Reply Last reply
            0
            • D Offline
              D Offline
              doozii
              wrote on 12 Mar 2014, 04:10 last edited by
              #6

              Thank you for your reply andreyc. Can you provide info on exactly what/how to add the build step?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andreyc
                wrote on 12 Mar 2014, 05:19 last edited by
                #7
                1. Click on "Projects" icon on sidebar
                2. See the "Build Steps" in the "Build Settings"
                3. Click "Add Build Step" button
                4. Select "Custom build step"
                5. In the "Commands" field enter your copy command. Command only without args.
                6. In "Arguments" field enter %{sourceDir}/YourFile %{buildDir}
                7. Go back to "Edit" and try to build your project

                "Here is more info":https://qt-project.org/doc/qtcreator-3.0/creator-build-settings.html

                PS: I use Linux, so I did not try it to run on Windows. YMMV.

                1 Reply Last reply
                3
                • D Offline
                  D Offline
                  doozii
                  wrote on 12 Mar 2014, 05:49 last edited by
                  #8

                  Thats great! Now we are making progress. I tried to enter "copy" in the commands field but I got an error: The process copy exited with code of -1.

                  What is the correct copy command?

                  Sorry for all the trouble... just needing to learn this fast and cant find any good explanations on Google or StackOverflow or in the qt forum and have been searching for days.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andreyc
                    wrote on 12 Mar 2014, 15:25 last edited by
                    #9

                    I don't have an access to windows machine right now and don't remember the format of the copy command.
                    You can try to run copy /? in command prompt to see the correct format.

                    Could you show the full log message that you get in QtCreator on this error?

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      doozii
                      wrote on 12 Mar 2014, 15:34 last edited by
                      #10

                      Wait... are we talking about the OS copy command? Or something in QT Creator?
                      Yeah, Ill post

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        doozii
                        wrote on 12 Mar 2014, 15:41 last edited by
                        #11

                        11:38:39: Starting: "COPY" C:\WORKSPACE\MyProject\MyFile.json C:\WORKSPACE\build-MyProject-Desktop_Qt_5_2_1_MSVC2012_OpenGL_64bit-Debug
                        qtcreator_ctrlc_stub: Command line failed: COPY C:\WORKSPACE\MyProject\MyFile.json C:\WORKSPACE\build-MyProject-Desktop_Qt_5_2_1_MSVC2012_OpenGL_64bit-Debug
                        11:38:39: The process "COPY" exited with code -1.
                        Error while building/deploying project MyProject (kit: Desktop Qt 5.2.1 MSVC2012 OpenGL 64bit)
                        When executing step 'Custom Process Step'

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          doozii
                          wrote on 12 Mar 2014, 15:54 last edited by
                          #12

                          I ran the command directly on the command line and it worked just fine but not from QT Creator

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andreyc
                            wrote on 12 Mar 2014, 17:49 last edited by
                            #13

                            Do you have this file and this directory in place during build?
                            Another option is try to run dir instead of copy just to make sure that QtCreator sees the file and the directory the same way as you see them when you run command manually.

                            And yes these are OS commands.
                            You can create a script and put in your project directory and run it.
                            You will need to put full path to the script in the "Commands" field.

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              doozii
                              wrote on 12 Mar 2014, 18:12 last edited by
                              #14

                              Yes sir, everything is in place. When I run the copy form the command line it performs the copy. Do I need to setup something in QT Creator that tells it where the system OS commands are located? I see in Options > Environment >External tools but not sure what would need to go there. If I click Add >Tool it puts in a New Uncategorized tool with the executable cmd and arguments /c echo Useful text. Is this what QTC is missing? Some reference to where the COPY command is located?

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andreyc
                                wrote on 12 Mar 2014, 19:08 last edited by
                                #15

                                No you don't need to change the "External Tools"
                                Did you try to run dir command instead of copy?
                                I think copy is not located anywhere it is just part of cmd.exe
                                Which makes me think that maybe you should call cmd.exe with some options that will allow to execute copy.
                                Try cmd.exe /? and see if it has an option to run command from command line.
                                Something like
                                @
                                cmd.exe /c copy src dst
                                @

                                If it will work in command prompt then put cmd.exe into "Command" field and "/c copy src dst" into "Arguments" field in your "Custom build step".

                                1 Reply Last reply
                                0

                                3/15

                                11 Mar 2014, 21:23

                                12 unread
                                • Login

                                • Login or register to search.
                                3 out of 15
                                • First post
                                  3/15
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved