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

List:       kde-devel
Subject:    Re: strings and QStrings
From:       David Faure <david () mandrakesoft ! com>
Date:       2000-12-08 0:41:57
[Download RAW message or body]

On Friday 08 December 2000 00:16, Scott Manson wrote:
> On Thursday 07 December 2000 05:39 pm, robbie wrote:
> > Hi
> >
> > im writing a program and im trying to use this bit of code:
> > deviceedit->setText(get_default_drive());
> > All the code is fine but when i compile the app this error comes up:
> >
> > ghdparm-kde.cpp:123: no matching function for call to
> > `QLineEdit::setText (string)'
> > /usr/lib/qt2/include/qlineedit.h:135: candidates are: void
> > QLineEdit::setText(const QString &)
> >
> > I can see its wanting a QString rather than a string so i added this
> > into the code:
> 
> My STL experience leaves something to be desired
> IIRC there is a function to get a char * pointer out of a string
> not sure what it is is it c_str()?
> > QString defdrive=get_default_drive().c_str();
> > deviceedit->setText(defdrive);

Yes, but mind the encoding.
What you want is either
QString defdrive=QString::fromLatin1(get_default_drive().c_str());
or
QString defdrive=QString::fromLocal8Bit(get_default_drive().c_str());
or
QString defdrive=QString::fromUtf8(get_default_drive().c_str());

depending whether the encoding of the string is latin1, the locale
encoding, or utf 8.

If in doubt, well, clear the doubt :). No, I wanted to say, if in doubt,
use fromLocal8Bit().

-- 
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


>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

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

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