Results 1 to 11 of 11

Thread: On deployment, the program does not find text file dependencies

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default On deployment, the program does not find text file dependencies

    Hi there guys, I've made this program that reads and writes text files. When running the program from the IDE it finds the files without any problems however when I deploy the program and then try to access the same files I get the error message "Access denied". What could be causing this?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: On deployment, the program does not find text file dependencies

    Maybe you are trying to write to a file at its installation location instead of at a user writable location.

    Or you are using relative paths and haven't set the working directory correctly.

    Cheers,
    _

  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: On deployment, the program does not find text file dependencies

    TB1.jpgtb2.jpgThank you for your reply anda_skoa. YES, the files are in the same Dir is the executable, and the reason for that is that the program needs them to function properly. Users are not suppose to open or even see these files. I have attached a snap shot of where my executable is and the files are located inside the include folder. The code below shows how I reference the files.
    Qt Code:
    1. QFile Sourced_RFQ_File(QCoreApplication::applicationDirPath().append("/Include/Program_Files/RFQ_Files/Sourced_RFQs.txt"));
    2. if(!Sourced_RFQ_File.open(QFile::WriteOnly | QFile::Text))
    3. {
    4. QMessageBox msgBox_2;
    5. msgBox_2.setText("Sourced RFQs file could not open reading...");
    6. msgBox_2.exec();
    7. return;
    8. }
    9. QTextStream outStream(&Sourced_RFQ_File);
    To copy to clipboard, switch view to plain text mode 
    Last edited by ayanda83; 30th January 2017 at 12:17.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: On deployment, the program does not find text file dependencies

    What does it mean "Users are not suppose to open or even see These files." ? How do you control it ?

  5. #5
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: On deployment, the program does not find text file dependencies

    I mean these .txt files are system dependencies (i.e. the system doesn't function properly without them). They are not meant to be accessed by users, hence I put them in the installation folder.

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: On deployment, the program does not find text file dependencies

    So you are using the system access protection mechanisms. The program has such permissions as the user. The program can not write to the file because user do not have permission. For the test run the program as an administrator.

  7. #7
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: On deployment, the program does not find text file dependencies

    Thank you for your reply. Do you have any suggestions for my problem?

  8. #8
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: On deployment, the program does not find text file dependencies

    Use encrypted QSettings.

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: On deployment, the program does not find text file dependencies

    Thank you for your reply. Do you have any suggestions for my problem?
    If this is Windows, you need to use a user-writable location for these files. Windows 7+ does not allow the user to create files in the installation directory; if the file is already there, -sometimes- Windows will let a program modify the file (i.e. write to it) without admin permission, but this can depend on the access rights for the user. If the user is working in an organization with a centrally-controlled IT policy, often users will have no permission to modify anything in the install folder.

    There are at least two ways around this:

    1 - Your installer can create any needed files at install time. I do this for my app's license key file - the installer copies an empty file to the install directory. Installations usually run with elevated permission, so can create files in the app directory. Of course, if the organization doesn't allow the user to write to this location during normal runtime, this won't work.

    2 - Use QStandardPaths to identify a location that -can- be used at runtime. If the files need to be shared by all users, then QStandardPaths::AppDataLocation or QStandardPaths::AppConfigLocation (Qt >= 5.5) would be the first choice. Otherwise, a user-specific location could be used: QStandardPaths::ConfigLocation, QStandardPaths::DocumentsLocation, or QStandardPaths::HomeLocation.

    In our case, the program license key is written by the user at runtime, not during installation. So, we use a series of fallbacks when we try to write the license key file. We first try to write it to the empty file we install. If that fails, we try to create a new app folder and file in AppData. If that fails, we try the user's config directory, and so forth. Typically our apps are installed on a single user machine, so writing to the user-specific directory as a last resort usually doesn't cause a problem. When we need to check the license at runtime, we follow the same fallback procedure, looking for a valid license file in each of the locations in turn. We wrap the whole thing in a CheckLicense class so the apps don't have to worry about the details.

    And as Lesiok says, if you don't want users to touch the data, use encryption.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. The following user says thank you to d_stranz for this useful post:

    ayanda83 (31st January 2017)

  11. #10
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: On deployment, the program does not find text file dependencies

    Thank you for your reply d_stranz, very informative. You helped solve my problem, I really do appreciate it.

  12. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: On deployment, the program does not find text file dependencies

    Quote Originally Posted by ayanda83 View Post
    YES, the files are in the same Dir is the executable
    Assuming one can write to an installation location is a problematic Windows developer trait.
    Any operating system worth that term will have file access permission of some sort, which usually do not permit write access to installation locations.

    Hence why there are easily accessible user writable locations, such as QDir::home() or various locations offered through QStandardPaths.

    Quote Originally Posted by ayanda83 View Post
    and the reason for that is that the program needs them to function properly
    Then you need to create them when needed, e.g. by creating them programmatically, copying them from an installation location, or extracting them from a Qt resource location.

    Quote Originally Posted by ayanda83 View Post
    Users are not suppose to open or even see these files
    That's going to be very difficult for systems that allow users file system access, e.g. through a file manager.

    Quote Originally Posted by ayanda83 View Post
    The code below shows how I reference the files
    For reading this is trivial, just put it into a Qt resource. Those are not real files on the file system and thus not visible to the user.

    But files you need to write to will be in some place visible to the user, unless the system hides files, e..g. on some mobile platforms.

    Cheers,
    _

  13. The following user says thank you to anda_skoa for this useful post:

    ayanda83 (1st February 2017)

Similar Threads

  1. Program doesn't find .txt file when started directly.
    By robgeek in forum Qt Programming
    Replies: 3
    Last Post: 18th August 2015, 14:28
  2. Replies: 16
    Last Post: 10th March 2013, 15:56
  3. Replies: 2
    Last Post: 22nd September 2012, 02:18
  4. Replies: 3
    Last Post: 3rd May 2009, 09:58
  5. What are the dependencies that a .exe file needs??
    By srohit24 in forum Installation and Deployment
    Replies: 5
    Last Post: 5th March 2009, 18:25

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.