PDA

View Full Version : Qstring vs string



cbarmpar
31st August 2008, 20:53
Hi all,

I am new to Linux , c++ and qt.

What I don't understand is why in most of the examples we use the Qstring class and not the normal c++ String class?

IS it possible to program the normal c++ way without using the relevant Qxxx Classes?

Many thanks in advance.

wysota
31st August 2008, 21:23
1. C++ doesn't contain a String class, STL does
2. STL String is 8-bit based whereas QString is Unicode based, thus we can express things with QString which we wouldn't be able to express with std::string
3. QString is much faster in many ways than std::string
4. QString has many functionality std::string doesn't have
5. QString has practically all useful functionality of std::string

I really advise to use QString in Qt based apps whenever you can. You'll be using it implicitly as all Qt classes tend to take text as QString although compilers can convert to QString from const char* implicitely, so you don't actually have to write "QString" in your code. But you'll be wasting cpu cycles and functionality if you don't - QString is std::string compatible, but not vice-versa.