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. QFile::handle() returns -1 for files in resource
Forum Updated to NodeBB v4.3 + New Features

QFile::handle() returns -1 for files in resource

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 6.0k 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.
  • M Offline
    M Offline
    moo1
    wrote on last edited by
    #1

    It seems QFile::handle() returns -1 for files in resource. It's not mentioned in the doc but is this expected behavior? I was hoping to get a valid file descriptor so that I can use other API that takes fd.

    I'm sure the file was opened successfully as open() returned true. I tested on Ubuntu Linux with Qt 4.7.0.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      Immii
      wrote on last edited by
      #2

      Documentation says :
      If the file is not open, or there is an error, handle() returns -1.
      So I will say please re check if the file is really open

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xsacha
        wrote on last edited by
        #3

        Are you sure you are using the same file id?

        I mean you have a QFile variable and are using handle() on it after open()? Not just QFile::handle() as per topic.

        • Sacha
        1 Reply Last reply
        0
        • V Offline
          V Offline
          vcsala
          wrote on last edited by
          #4

          Maybe some code snippets would be helpful to see what is the issue

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            For data in a Qt resource file (filename is ":/path/to/resource") there is no underlying file (the data itself is actually compiled into your executable), so there is no file descriptor either. You can use Qt resource only within Qt itself or extract the data to an array/QByteArray and hand that bunch of bytes over to your legacy code.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • M Offline
              M Offline
              moo1
              wrote on last edited by
              #6

              Thanks Volker, that makes sense.

              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