Where is my file



  • I have a custom read-only file containing some data that I need to open in my mobile app. I added it as a resource and it shows up in the "other files" section of resources. How do I get the path to this file on the device?


  • Moderators



  • @koahnig

    This is helpful, although I'm not sure I understand all of the terminology. Is it saying that all of the resources are compressed inside of my excecutable binary? If so, how do I put it into the ordinary file system? Is that what the external binary resources section is about?

    My challenge is that I'm trying to integrate some C code that I got from another source, which is not built on Qt, and it requires a full canonical path to the file. After reading this article, I was able to locate the file using QFile. But when I tried obtaining the canonical path using the code below, it simply expands as ":/myFile.dat".

    QDir localdir("://");
    QString myfile = localdir.canonicalPath();
    myfile.append("myFile.dat");
    

  • Moderators

    @kgregory said in Where is my file:

    @koahnig

    This is helpful, although I'm not sure I understand all of the terminology. Is it saying that all of the resources are compressed inside of my excecutable binary? If so, how do I put it into the ordinary file system? Is that what the external binary resources section is about?

    An resource I would simply use for smaller dataset, since it is part of your executable. I have never worked with external resource files.

    @kgregory said in Where is my file:

    My challenge is that I'm trying to integrate some C code that I got from another source, which is not built on Qt, and it requires a full canonical path to the file. After reading this article, I was able to locate the file using QFile. But when I tried obtaining the canonical path using the code below, it simply expands as ":/myFile.dat".

    QDir localdir("://");
    QString myfile = localdir.canonicalPath();
    myfile.append("myFile.dat");
    

    Most likely there are other issues arising when you try make your internal resources accessible for other code. What you could do is reading the internal resource and storing it, perhaps on temporary space, somewhere.



  • @kgregory Are you sure you really need to deploy the read-only file as part of your application binary? that's what's happening when you create a resource file in Qt, all the items added to the resource file are "embedded" in your executable file. A resource file is mostly intended for items such as icons, little images for buttons, translation files, so having just them inside your binary file saves headaches on deployment.



  • As a follow up, if you cannot deploy your read-only file as a separate item and it will end up as part of the resource file, you can read it like this:

    QFile file(":/myFile.dat");
    

    Please read again the documentation about resources pointed out in previous post.



  • OK, I wound up putting it in the the resource file and then copying it to a temporary location before it is needed. This appears to work.

    On to new problems now...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.