Archit J
Archit J

Reputation: 150

Passing char* to QString

I am working on a module in which GUI and back-end interact by message passing. I initialised a char* as nullptr. GUI takes a QStringList which is tokenized. I cannot do the changes in the tokenized list. I receive a "(null)" in the list. Now I feel like by comparing to "(null)" is not the way to go. Is there any initialisation for char* which would be taken as an empty string by QString?

Upvotes: 0

Views: 358

Answers (2)

kzsnyk
kzsnyk

Reputation: 2211

Not sure to understand what you want but if i am not mistaken :

char *c = nullptr;
QString str(c);

str.isEmpty(); // return true

Upvotes: 1

R Sahu
R Sahu

Reputation: 206577

Use an empty string when constructing a QString when the pointer is NULL.

QString obj = (ptr == nullptr? QString("") : QString(ptr));

And then use obj.

Upvotes: 3

Related Questions