[Qt-interest] QFile private member

Scott Aron Bloom Scott.Bloom at sabgroup.com
Tue Feb 10 23:00:18 CET 2009


 -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Pete Christensen
> Sent: Tuesday, February 10, 2009 1:54 PM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] QFile private member
> 
> Scott Aron Bloom wrote:
> >
> >> -----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
> >
> >
> 
> OK, cool. Andrew called it and Scott actually figured out that I know
> nothing about C++ and then told me how to assign an actual object to a
> pointer. (I think that's how to describe what's happening here.)
> 
> The other suggestions, including Andreas', using reference "file
QFile"
> and not pointer "file * QFile" all fail to compile with the same
error.
> I'm pretty sure I'd need an explicit copy constructor to get that to
> work. (And I'm finding there's nothing "plain" about C++, Andreas :))
> 
> Thanks guys. Hopefully I can actually figure out how to use this
pointer
> I've now got.
> 
> Re: destructor: will-do, Bob.

Good luck... However, I seriously recommend you take a basic C++ class
first..  Even a C++ class using QT, but your fundamentals are weak and
need work

Scott




More information about the Qt-interest-old mailing list