[Qt-interest] QFile private member
Andreas Pakulat
apaku at gmx.de
Wed Feb 11 00:15:54 CET 2009
On 10.02.09 16:54:00, Pete Christensen wrote:
> 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.)
As was already said, this might get you into new issues if you don't
understand C++ that well.
> The other suggestions, including Andreas', using reference "file QFile"
This works:
,----
| #include <QtCore>
|
| class MyFile
| {
| public:
| MyFile( const QString& f ) : file(f) { }
| QString fileName() { return file.fileName(); }
| private:
| QFile file;
| };
|
| int main(int argc, char** argv)
| {
| MyFile f("foobar");
| qDebug() << f.fileName();
| }
`----
Note that the file member variable is directly initialized with the
QString member. This does nothing other than calling the existing
QFile(const QString&) constructor. Unless I totally misread your
original post this is what you wanted.
> 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 :))
No you don't, you just need to use an initializer list and the right
constructor.
And btw, if you find C++ "not so plain", then I suggest reading some
ruby or assembler ;)
Andreas
--
You will be reincarnated as a toad; and you will be much happier.
More information about the Qt-interest-old
mailing list