Solved How to declare a QFile as a member class
-
In the header of the class i did
header
QFile file; //File to write QDataStream out; //To write in the file void create_file(); //Function to create in a file void write_file(unsigned char *p); //Function to write in a file receive a pointer to the array buffer void delete_file(); //Function to delete in a file
cpp
//Function to create a File void backend::create_file() { //Name of the file file("text.txt"); //Creation of the file, mode writeonly file.open(QIODevice::WriteOnly); } //Function to write in a File void backend::write_file(unsigned char *p) { out(&file); } //Function to delete a File void backend::delete_file() { }
In the header i can't declare mi fle like this QFile file("text.txt");
And in the cpp file("text.txt"); gives me error/home/pasante/Escritorio/PIZZA/backend.cpp:1521: error: no match for call to ‘(QFile) (const char [9])’
file("text.txt");
^out(&file); this gives me error too, but i can't put it in the headrer
/home/pasante/Escritorio/PIZZA/backend.cpp:1531: error: no match for call to ‘(QDataStream) (QFile*)’
out(&file);
^ -
@aurquiel
Hi
QFile can also set the info via functions
http://doc.qt.io/qt-5/qfile.html#setFileNameand for out(&file);
http://doc.qt.io/qt-5/qdatastream.html#setDeviceThe reason it dont work is that the first syntax is the constructor and that cant work the same when in .h
but both classes have function to set it.
Alternativ u can new them but its better with the setX functions. ( IMHO)