[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde2-porting
Subject:    Re: QString pointers not a good idea??
From:       David Faure <david () mandrakesoft ! com>
Date:       2000-12-05 22:02:25
[Download RAW message or body]

On Tuesday 05 December 2000 21:33, Christopher Wiegand wrote:
> > On Monday 04 December 2000 23:22, Christopher Wiegand wrote:
> > > Okay, I'm having lots of fun porting Geheimnis (a GUI pgp/gpg shell
> > for KDE
> [snip]
> > > now it appears I should have a member variable in the class called
> > > profileName, and use it like such:
> > > 
> > > QString profileName; // in header file
> > > 
> > > profileName = i18n("New Profile"); // sure hope this works!
> > It does.
> > 
> > > loadProfile(&profileName);
> > 
> > You'll save yourself trouble by using QStrings as objects _everywhere).
> > This means, loadProfile should take a "const QString &" as parameter.
> > 
> > QString are implicitely shared, so even "QString parameter" doesn't
> > involve a deep copy.
> >
> > -- 
> > David FAURE, david@mandrakesoft.com, faure@kde.org
> 
> Okay, so am I passing around a pointer or a full copy of the QString? I
> guess I can just rewrite things so that I use the object instead of the
> pointer, but does anyone have a reason why it's now this way? 

It's just easier to write myString.blah() everywhere
than myString->blah, with a minor risk that myString is 0L.
But as Stephan said, it's no obligation.

> I thought that
> pointers were "good" to pass, and one was supposed to avoid passing the actual
> data (in this case a QString & versus a QString *).

[const] QString & is a reference, it doesn't copy the data.

Have a look at some KDE source code, you'll see that it's all written
with const QString & for input parameters, QString for return values,
and QString for variables. It's just easier,

-- 
David FAURE, david@mandrakesoft.com, faure@kde.org
http://www.mandrakesoft.com/~david/, http://www.konqueror.org/
KDE, Making The Future of Computing Available Today
See http://www.kde.org/kde1-and-kde2.html for how to set up KDE 2
_______________________________________________
kde2-porting mailing list
kde2-porting@master.kde.org
http://master.kde.org/mailman/listinfo/kde2-porting

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic