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. [SOLVED] QFile open problem with path to resource file
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QFile open problem with path to resource file

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 5.4k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    ningu
    wrote on last edited by
    #1

    Hi,

    I have this code:

    @QFile file(fileName);
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
    qDebug() << "Could not open file:" << file.errorString();
    file.close();
    return;
    }@

    If filename = "/absolute/path/to/appSettings.json" it opens the file.
    If filename = ":/config/appSettings.json" it throws an Unknown error.

    The thing is, I have the same code for reading the file, and it works with both versions of the path, so the qrc file is set correctly. I checked permissions and even changed them to -rwxrwxrwx but still get the same error (actually it would not work with absolute path if this were the problem, and it does).

    Any clues on what may be going on?

    Cheers!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thEClaw
      wrote on last edited by
      #2

      Maybe you just cannot write into your executable? That might throw off addresses and render your application useless.
      I am only assuming, though, since I have never tried to use a resource file for writing.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Buckets
        wrote on last edited by
        #3

        When I use a .qrc file, I changed the prefix to / so when I want any of the files it is just ":/filename".

        not sure if this is the issues but is the prefix "/config/" or "/config"?

        ba ba ba
        ba na na na

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Resources files are read-only (and they are compiled in your binary executable).

          If you need a read-write solution, you should copy the resource file somewhere (QStandardPaths comes to mind) and use that file instead.

          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
          2
          • N Offline
            N Offline
            ningu
            wrote on last edited by
            #5

            Ah... ok. Thanks a lot!

            1 Reply Last reply
            0

            • Login

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