Results 1 to 2 of 2

Thread: simple QString comment

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default simple QString comment

    may sound trivial to many but...
    Qt Code:
    1. QString thing("");
    To copy to clipboard, switch view to plain text mode 
    makes an empty but non-null string

    calling clear() on is makes it both empty and null.
    I'm sure that's what it's meant to do but does that make sense?
    wouldn't be better to have a clear() that empties the string and a reset() to null it?

    I recursively use a string, and need it emptied - do I have to empty my string with thing = "";

    maybe it's a bit pedantic?
    tell me it's pedantic.
    thanks
    K

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: simple QString comment

    calling clear() on is makes it both empty and null.
    Should not.
    From the docs:
    void QString::clear ()

    Clears the contents of the string and makes it empty.
    bool QString::isNull () const

    Returns true if this string is null; otherwise returns false.

    Example:

    QString().isNull(); // returns true
    QString("").isNull(); // returns false
    QString("abc").isNull(); // returns false

    Qt makes a distinction between null strings and empty strings for historical reasons. For most applications, what matters is whether or not a string contains any data, and this can be determined using isEmpty().

    See also isEmpty().

  3. The following user says thank you to high_flyer for this useful post:

    fnmblot (3rd August 2006)

Similar Threads

  1. simple pointer question
    By mickey in forum General Programming
    Replies: 6
    Last Post: 16th June 2006, 09:19
  2. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 08:55
  3. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10
  4. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52
  5. [SOLVED] Widget plugin ... how to ?
    By yellowmat in forum Newbie
    Replies: 10
    Last Post: 29th January 2006, 20:41

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.