Search code examples
c++qtqt5qfileqtextstream

QFile init/assignment op issue when objects are class members


So i have a QFile and QTextStream member as part of my class... trying to init. them together in my constructor:

Class.h:

QFile _file;
QTextStream _textstrm;

Class.cpp:

_file = QFile (/*file name*/);
_file.open(/*set stuff*/);
_textstrm = QTextTream ( &_file );

And the comp error i get, C2248, says the objects to have access to the operators in their own class..


Solution

  • The problem is that you are creating a new object and you are adding an attribute that has no access, you must use the functions provided by the object.

    _file.setFileName(/*file name*/);
    _file.open(/*set stuff*/);
    _textstrm.setDevice( &_file );