Results 1 to 4 of 4

Thread: Create files required by application from resource files?

  1. #1
    Join Date
    Jun 2012
    Posts
    202
    Thanks
    22
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Create files required by application from resource files?

    My application needs some files to executed properly. The files are needed for initialization of an embedded interpreter and the library functions only support passing a filename, not an open file descriptor.

    I can have the files live in a known directory, but they could get accidently deleted by accident. I'm wondering if there's a good way to create the files from Qt resources?

    I can have a trivial Qt method that copies the files at startup from their resource definitions into temporary files and use the copies.

    Is there a better way?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,155
    Thanks
    296
    Thanked 854 Times in 841 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Create files required by application from resource files?

    Resources are compiled and linked into your program at build time. Are these configuration files constant (i.e. the same for every installation of the program)? If so, then you can just add them as resources in the QRC file and then can use them at runtime just like any other disk-based file. Just open them with the proper resource URL (qrc:///...) or file path (:/...) like you would when loading an icon. No need to copy them to a temporary file.
    <=== 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.

  3. #3
    Join Date
    Jun 2012
    Posts
    202
    Thanks
    22
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Create files required by application from resource files?

    Only Qt objects like QFile can use files saved as resources. C calls like Tcl_EvalFile require a name of file that exists--it can't be a Qt resource like :/myfile.tcl


    Added after 48 minutes:


    Quote Originally Posted by davethomaspilot View Post
    Only Qt objects like QFile can use files saved as resources. C calls like Tcl_EvalFile require a name of file that exists--it can't be a Qt resource like :/myfile.tcl
    In other words, APIs for library calls won't work with built-in resources. Does that make sense?

    For example,

    I have several Tcl files that get executed via Tcl_EvalFile(interp, filename) .

    "filename" can't be something like ":/myfile.tcl". The API provide by the Tcl C library won't know what to do with a colon prefixed file name.

    So, I have to have a copy of the files parked someplace where they can be accessed by file system filename.
    Last edited by davethomaspilot; 7th September 2022 at 01:57.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,155
    Thanks
    296
    Thanked 854 Times in 841 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Create files required by application from resource files?

    Only Qt objects like QFile can use files saved as resources.
    Yes, that's correct. QFile (which probably uses QResource internally) recognizes the special syntax of qrc:// or :/ and opens the in-memory resource that is loaded when the program loads.

    So use QFile to open your resource and copy it into a file created by QTemporaryFile. See this: QTemporaryFile::createNativeFile(). You should then be able to pass the file name returned by QTemporaryFile::fileName() to your Tcl library. When you delete the QTemporaryFile instance, the file will be deleted as well.
    <=== 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.

Similar Threads

  1. Resource files not showing on Ubuntu 16.04
    By EVARATE in forum Newbie
    Replies: 1
    Last Post: 15th April 2020, 00:28
  2. integrated + binary resource files
    By Le_B in forum Qt Quick
    Replies: 0
    Last Post: 5th June 2011, 17:45
  3. QDir::setCurrent with resource files
    By LarryERamey in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2011, 03:21
  4. Replies: 1
    Last Post: 24th October 2009, 16:11
  5. How to compile qt resource files?
    By yangyunzhao in forum Qt Programming
    Replies: 1
    Last Post: 10th August 2009, 07:46

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.