[Qt-interest] QFile private member

Stanislas Polu spolu at stanford.edu
Tue Feb 10 21:20:59 CET 2009


First: You should rather make privateFile a subclass of QFile
class PrivateFile : public QFile...

Nevertheless in your case : I guess that would be :

PrivateFile::PrivateFile(const QString &fileName)
       : file(QFile(fileName))
{
}

-stan


2009/2/10 Pete Christensen <qt at graffiti.graceland.ca>

> 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? I can find
> nothing in the documentation nor in this newsgroup that tells me how. Am
> I the only one who has wanted to do this? Qt 4.4.3.
>
> privatefile.h
>
> #ifndef PRIVATEFILE_H_
> #define PRIVATEFILE_H_
>
> #include <QString>
> #include <QFile>
>
> class PrivateFile {
> public:
>        PrivateFile(const QString &fileName);
> private:
>        QFile file;
> };
>
> #endif
>
> privatefile.cpp
>
> #include "privatefile.h"
>
> PrivateFile::PrivateFile(const QString &fileName) {
>        file.setFileName(fileName);
>        //??
> }
>
> Compiler complains:
> /usr/include/qt4/QtCore/qfile.h:191: error: 'QFile::QFile(const QFile&)'
> is private
>
> !!!!!!!!!!!!
>
> How can this be done? There is something wrong with the way I'm
> declaring file member in privatefile.h, but I do not understand what.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090210/98d36555/attachment.html 


More information about the Qt-interest-old mailing list