Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove empty and null strings from QStringList?

I have a QStringList and I need to clean some meaningless elements : the empty and the null strings.

I could not find a QStringList shortcut function for that.
What is the simplest way to clean the empty/null strings ?

like image 502
ymoreau Avatar asked Nov 01 '25 13:11

ymoreau


1 Answers

myQStringList.removeAll(QString("")); // Returns the number of entries removed

Empty string QString("") and null string QString() both return true when compared to an empty string.
Then the test of QList::removeAll(const T &value) will remove both empty and null strings from the list.

like image 136
ymoreau Avatar answered Nov 04 '25 03:11

ymoreau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!