Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Qt return empty QString

Tags:

c++

qt

qstring

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?

like image 989
Normal People Scare Me Avatar asked May 04 '13 17:05

Normal People Scare Me


1 Answers

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.

like image 155
Frank Osterfeld Avatar answered Sep 22 '22 15:09

Frank Osterfeld