C++ Qt return empty QString

14,096

The idiomatic way to create an empty QString is using its default constructor, i.e. QString(). QString() creates a string for which both isEmpty() and isNull() return true.

A QString created using the literal "" is empty (isEmpty() returns true) but not null (isNull() returns false).

Both have a size()/length() of 0.

Share:
14,096
Normal People Scare Me
Author by

Normal People Scare Me

I'm interested in Python, Perl, C, C++, LISP, PHP and Fortran.

Updated on June 15, 2022

Comments

  • Normal People Scare Me
    Normal People Scare Me almost 2 years

    I made a function which returns a QString. At some points in my function it should return an empty QString.

    Just returning "" doesn't work. When I use QString::isEmpty() it's not. My "emergency plan" was to return an "empty" string and check with it whether the text is "empty". But I don't think that's good style.

    So how do I return an empty QString?