Search code examples
c++qtqstringqlist

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 ?


Solution

  • 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.