Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
fopen in C++ application?
I want to use fopen, I've included the headers:
#include <stdio.h> #include <stdlib.h>
In my source I have declared:
FILE* fp = fopen("file.txt", "rt");
no matching function for call to 'fopen'
Why? I thought fopen was part of the standard C library?
I need a file handing routine that I can translate the returned file pointer into a handle and then back from a handle to a file pointer so I can pass the handle back and forth between the application and another module.
The include is <cstdio>.
Since you are using Qt, why not use QFile ?
SPlatten last edited by SPlatten
@SGaist , Thank you, is it possible to get a file handle from QFile so that when the object goes out of scope I can pass the handle back in on another call and get access to the file without having to open it again?
Yes you can get it but if the QFile goes out of scope, the handle won't be valid anymore.
What is your exact use case ?
I'm writing an application that will provide native functions and access to the OS GUI it includes services such as file access and database access. I've completed the database service which works well. I want to provide file access which is as efficient a possible, so once the file is opened I want it to stay opened until a request is sent to close the file.
So what's wrong with a QFile object then?
If I declare it as global then nothing, but if it's declared in a function scope the file will automatically be closed when the object goes out of scope.
You're aware you can create any object on the heap?
QFile *f = new QFile ...
You only have to make sure to delete it once you don't need it anymore.
Yes, sorry, juggling lots of things atm, not thinking clearly.