Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Resource Files



  • Hello, I am writing a c++ console application in my Linux environment.
    I want to reference an XML file so that when I run the executable, it knows where to find it.
    I am also using Tiny XML library. So when I open a file to edit/read I use TiXmlDocument doc ("Profile.xml"); . I was reading in other blogs to use QTFile to open a file, but I am using the tinyXML file so I'm not sure if I can use this.
    In my code, after I run the TiXmlDocument line, I am able to read the file. When I write to the Profile.xml file, make changes then delete the xml file before I save it with the same name.
    How do I reference this file correctly when running the executable file?


  • Moderators

    @user614 said in Resource Files:

    How do I reference this file correctly when running the executable file?

    You can't use Qt resource system for that, because it is read only. However, you have many other options:

    • add a default xml file to Qt resource system, then on first run of your app copy that file on disk - and open there using TiXmlDocument. This is probably the easiest option
    • deploy your default xml file together with your app. How - that depends entirely on how you distribute your application. Put it in an .AppImage, Debian or RPM package. Or package it inside some installer (for example using Qt Installer Framework). Then you will know where the package is installed and what the path to the file will be

    If you need to place the file relative to your application binary, you can use application dir path to know where your binary is (as opposed to current directory).


Log in to reply