How to declare a QFile as a member class

  • In the header of the class i did


    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


    //Function to create a File
    void backend::create_file()
        //Name of the file
        //Creation of the file, mode writeonly;
    //Function to write in a File
    void backend::write_file(unsigned char *p)
    //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])’

    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*)’

  • Qt Champions 2017

    QFile can also set the info via functions

    and for out(&file);

    The 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)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.