[Qt-interest] QFile private member
Pete Christensen
qt at graffiti.graceland.ca
Tue Feb 10 22:31:42 CET 2009
andrew.m.goth at l-3com.com wrote:
> Pete Christensen wrote:
>> OK, I give up, I can not do this. How do I declare a private member
>> variable of type QFile and initialize it in the constructor?
>
> Are you sure you want QFile and not QFile*?
>
>> Compiler complains:
>> /usr/include/qt4/QtCore/qfile.h:191: error:
>> 'QFile::QFile(const QFile&)'
>> is private
>
> The gripe is against the header file, not the implementation of the
> constructor. Specifically the complaint is that the QFile copy
> constructor is private. Why would that be a problem? It looks to me
> that it's trying to make a default copy constructor for your class, but
> it can't since it would rely on copy constructors for all data members
> of your class. You could explicitly define a copy constructor for your
> class, or you could just switch to QFile*, which can be copied without
> incident.
>
OK, it's starting to make a little sense. I looked up "copy constructor".
"A copy constructor is generally needed when an object owns pointers or
non-shareable references, such as to a file, in which case a destructor
and an assignment operator should also be written."
So now I'm pretty sure QtCore does things like:
190 private:
191 Q_DISABLE_COPY(QFile)
192 };
(this from qfile.h) to explicitly get the compiler to barf in situations.
I'll look into this destructor/assignment operator thing.
Regarding subclassing, I'm not actually creating a new QFile type, this
was just the simplest I could get my code to communicate my problem.
Eventually I need to read the file in a thread.
More information about the Qt-interest-old
mailing list