Results 1 to 2 of 2

Thread: Qstring vs string

  1. #1
    Join Date
    Aug 2008
    Posts
    52
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qstring vs string

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qstring vs string

    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.

  3. The following 2 users say thank you to wysota for this useful post:

    cbarmpar (3rd September 2008), davidovv (29th September 2011)

Similar Threads

  1. How to convert from QString to string ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 1st December 2010, 01:50
  2. Reading from sockets in a multithreaded program
    By KoosKoets in forum Qt Programming
    Replies: 9
    Last Post: 4th April 2007, 20:43
  3. Problem in converting QString to QChar array?
    By KaKa in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2007, 00:38
  4. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  5. Replies: 1
    Last Post: 30th June 2006, 05:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.