The qstringlist class provides a string list.
Inherited from qlist <qstring>, it provides access and fast insertion and Removal Based on quick indexing.
Its member functions are used to operate the string list, as shown in figure
Append (), insert (), replace (), removeall (), removeat (), removefirst (), removelast (), and removeone ()
1. Add a string
You can use append () or <, as shown in figure
Qstringlist fonts;
Fonts <"Arial" <"Helvetica" <"times" <"Courier ";
// Fonts: ["Arial", "Helvetica", "Times", "Courier"]
2. Use join () to merge strings ()
Qstring STR = fonts. Join (",");
// STR = "Arial, Helvetica, times, courier"
3. Split string
Qstring STR = "Arial, Helvetica, times, courier ";
Qstringlist list1 = Str. Split (",");
// List1: ["Arial", "Helvetica", "", "Times", "Courier"]
Qstringlist list2 = Str. Split (",", qstring: skipemptyparts );
// List2: ["Arial", "Helvetica", "Times", "Courier"]
That is to say, if qstring: skipemptyparts exists, null items will not appear in the result. By default, null items are retained.
4. Index
The indexof () function returns the first index of the given string.
The lastindexof () function returns the last index of the string.
5. replaceinstrings ()
Qstringlist files;
Files <"$ qtdir/src/MOC. Y"
<"$ Qtdir/src/MOC. L"
<"$ Qtdir/include/qconfig. H ";
Files. replaceinstrings ("$ qtdir", "/usr/lib/Qt ");
// Files: ["/usr/lib/QT/src/MOC. Y",...]
6. Filter ()
You can extract a new list that contains only one specific string (or matches a specific regular expression ):
Qstringlist list;
List <"Bill Murray" <"John Doe" <"Bill Clinton ";
Qstringlist result;
Result = List. Filter ("bill ");
// Result: ["Bill Murray", "Bill Clinton"]