[Qt-interest] QFile private member

Scott Aron Bloom Scott.Bloom at sabgroup.com
Tue Feb 10 22:40:13 CET 2009



> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Pete Christensen
> Sent: 2009-02-10 13:32
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] QFile private member
> 
> 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.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
[Scott Aron Bloom] 
You are creating a new QFile, except by using QFile rather then QFile *.

Simply making it a QFile *, and then in the constructor, creating a
blank QFile...

file = new QFile;

You will solve all your issues...

Scott






More information about the Qt-interest-old mailing list