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");
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");
We had very strange problems with our application and finally traced it to the QFile/fdopen issue:
The problem with this code is that fclose(f) is called before the QFile object is destroyed, which is the wrong order: QTBUG-20372
...so either destroy the QFile object before calling fclose() or duplicate the file descriptor returned by QFile::handle():
P.S.: Those strange problems with our app showed up only on very few systems by a 10 second delay between a return statement at the end of a function and the actual return from that function. It was really weird. So this is an example of an "undefined behaviour" manifested in the real world :o)
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 thehandle
method returns an error.After that, you might reopen it with:
If you have the file name, why don't you simply use
?
Isn't it way simpler than creating the QFile, opening it, retrieving the handle, etc.?
And it is pretty bug-free...