Results 1 to 4 of 4

Thread: Files to a program

  1. #1
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Files to a program

    Hi,

    I'm writing here because I'm not really aware of the proper searching keywords. I would like to have some initializer files attached to my program. Qt's resource system is not the answer because I would like to have it just like a normal file (not compiled into the program). There I would store some variables or user-defined paths ect so these would be basically simple text files for storing not hard-coded values.

    Now my question is how to do this properly? Or simply define a relative path that will be valid from the exe and if this relative path is hard coded than simply that's it? I was just wondering if there is a better way by which when I compile the release version the necessary folders and files would be generated.

    The answer can be Qt-based, but I thought this should be a more general question.
    Szilvi

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Files to a program

    There are many solutions:

    Qt based
    You can use QSettings and save your file in the exe path.
    You can use QCoreApplication::applicationDirPath to know how there's you file.
    You can also use QDesktopServices

    General
    You can pass the path as command line arguments
    Last edited by mcosta; 19th July 2011 at 08:28. Reason: reformatted to look better
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Files to a program

    It looks I'm seaching for QSettings. I can see a small example that I seem to have understood at the end of a qtforum.org topic. (However I couldn't make that code work as QSetttings has no members called readEntry nor writeEntry and QString has no member named local8bit, so it is also a wonder for me why this should work.)

    Now do I see well that this will save settings into a qt-related folder?

    Could someone maybe write me a short fake code just to see the logic? I would like to make a portable application so I will have everything in a folder like this:
    myApp/
    .....settingFiles/
    ..........1st.txt
    ..........2nd.txt
    .....images/
    ..........img1.png
    ..........img2.png
    myApp.exe
    (necessary dlls)

    It is an application with a GUI.
    I would like to store the settings into the settingFiles folder where I will have settings not related to the environment but values that may control the application's work and they should be easilly changeable.

    Is there maybe a tutorial focusing on QSettings? I is represented in the built-in Application example but not very well explained.
    Last edited by szisziszilvi; 19th July 2011 at 12:30.
    Szilvi

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Files to a program

    the post is very old!!!

    however you can write code like this
    Qt Code:
    1. QString appPath = QApplication::applicationDirPath();
    2.  
    3. QSettings settings1 (appPath + "/settingFiles/1st.txt", QSettings::IniFormat);
    4. // Read data
    5.  
    6. QSettings settings2 (appPath + "/settingFiles/2nd.txt", QSettings::IniFormat);
    7. // Read data
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  5. The following user says thank you to mcosta for this useful post:

    szisziszilvi (20th July 2011)

Similar Threads

  1. Replies: 1
    Last Post: 17th April 2010, 00:12
  2. Replies: 12
    Last Post: 17th June 2009, 05:34
  3. Open multiple files with one program instance
    By Ginsengelf in forum Qt Programming
    Replies: 6
    Last Post: 16th March 2009, 14:08
  4. [Solved] Open files outside my program
    By Nykoo in forum Qt Programming
    Replies: 0
    Last Post: 27th January 2008, 16:13
  5. Replies: 2
    Last Post: 5th September 2007, 22:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.