Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, March 2002
QString <-> string


Message 1 in thread

Hi!

    I have the following question regarding Qt libraries and string
support. I have a project in Linux, where I most use string's because I
find their interfase  completely coherent with STL containers (which I
also use all the time). And also they provind a bunch of utilities to
manipulate them.

    So, It is frustrating that Qt does not provide (as far as I know) a
better way to do conversions between string's and QString's than doing

     string s="foo";
     QString qs=s.c_str();

     Why is it??? The char_traits for strings objects aren't specified
enough to warranty a good conversion (at least with ASCII chars)???

     Perhaps it is ugly, but if "string" header is present in a system
where Qt is installed, why not to add a QString constructor

       QString::QString(const string &);

     At least basic_string???

     Thanks in advance!

-- 
 [ signature omitted ] 

Message 2 in thread

Hi !

On Tue, 19 Mar 2002, Tessone, Claudio Juan wrote:

>      Perhaps it is ugly, but if "string" header is present in a system
> where Qt is installed, why not to add a QString constructor
> 
>        QString::QString(const string &);
> 
>      At least basic_string???

We are considering to add such convenience constructors like we did with
QMap<->std::map and QValueList<->std::list.
The problem with strings is the character set/range being used. For above
constructor to be safe, for example, we'd have to define the conversion
taking place when converting the 8 bit string to the 16 bit QString. This
is quite important with internationalization. Note that the constructor
accepting a const char* can be disabled by defining QT_NO_CAST_ASCII as
it's potentially dangerous, too. For this reason there are the static
fromLocal8Bit(), fromLatin1() and fromUtf8() functions that can be called
explicitly to be on the safe side.

Harri.