Search code examples
c++fileqtqfile

Convert QFile to FILE*


Is there another way to convet QFile to File? Different than this:

QFile myFile("goforward.raw");
int FileDescriptor = myFile.handle();
FILE* fh = fdopen(FileDescriptor, "rb");

Solution

  • I think you already know that you have the various open, read, etc. methods in QFile. That said, if the file is not opened, then the handle method returns an error.

    QFile myFile("goforward.raw");
    myFile.open(QIODevice::ReadOnly);
    int fileHandle = myFile.handle();
    

    After that, you might reopen it with:

    FILE* fh = fdopen(fileHandle, "rb");