当前位置:网站首页>Learning notes for qstringlist
Learning notes for qstringlist
2022-06-28 00:11:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Due to company projects , Start Study QT, Here are some study notes , After that, I forgot to read it . Simple notes , Do not blame it. . Reference blog :https://blog.csdn.net/u013360881/article/details/52170487
QStringList initialization
QStringList qstrList;
qstrList<<"Android" << "Qt Creator" << "Java" << "C++";
QStringListIterator strIterator(qstrList);
while (strIterator.hasNext())
qDebug() << strIterator.next() << endl;Here we use QStringList add to QString character string , use << To add a string , amount to Java in List Of add() Method .
Let's learn about QList Methods
1. Add string append() QStringList Can pass append(), Or use << To add List Elements , Such as
qstrList.append("python");
qstrList << "PHP" ;2. Insert string insert() Insert string insert Method can insert a string into the... We specify list The location of :
qstrList.insert(0,"C#");The first parameter is where we want to insert , The following parameters represent the values we want to insert . 3. Replace string replace() adopt replace() Method we can replace list The value of a position in the
qstrList.replace(0,"Web");The first parameter is the position we want to replace , The following parameters represent the values we want to replace . 4. Delete string removeAt(), removeFirst(), removeLast(), and removeOne() We can use the method name , Infer the specific function of the method , Select the corresponding method according to the actual needs : Here's to say removeOne() Method , He means to delete a specific value , The parameter is us list Contents of Li , Its definition is : bool removeOne(const T &value) , The return value is bool type , Let's write an example of usage
bool isflag = qstrList.removeOne("C#");// Delete a specified element , Delete successful return true, Delete failed return fasle
qDebug() << isflag << endl;
int n = qstrList.removeAll("Java");// Delete all specified elements , Returns the number of deleted elements
qDebug() << n << endl;
qstrList.removeAt(2);// Delete the third element
qstrList.removeFirst();// Delete first element
qstrList.removeLast();// Delete the last element Next let's learn QStringList Methods
1. Merge strings using join( )
QString str = fonts.join(",");
// str == "Android,Qt Creator,Java,C++"2. Split string
QString str = "Android,Qt Creator, ,Java,C++";
QStringList list1 = str.split(",");
// list1: [ "Android", "Qt Creator"," ", "Java", "C++" ]
QStringList list2 = str.split(",", QString::SkipEmptyParts);
// list2:[ "Android", "Qt Creator", "Java", "C++" ]That is to say, if there is QString::SkipEmptyParts, Empty items will not appear in the result . By default , Blank items are reserved 3. Indexes IndexOf() The index() function returns the index of the first occurrence of a given string . and lastIndexOf() function , Returns the index of the last occurrence of a string .
QStringList qstrList;
qstrList<<"Java" << "Android" << "Qt Creator" << "Java" << "C++";
int index = qstrList.indexOf("Java");// return 0
int index = qstrList.indexOf("Java");// return 34. Replace replaceInStrings()
QStringList files;
files << "$file/src/moc/moc.y" << "$file/src/moc/moc.l" << "$file/include/qconfig.h";
files.replaceInStrings("$file", "/usr/file");
// files: [ "/usr/file/src/moc/moc.y", ...]5. Filter filter() Allows you to extract a new list containing only those strings containing a specific string ( Or match a specific regular expression ):
QStringList list;
list << "Bill Murray" << "John Doe" << "Bill Clinton";
QStringList result;
result = list.filter("Bill");
// result: ["Bill Murray", "Bill Clinton"]
// When comparing strings
//Qt::CaseSensitive Search is case sensitive
//Qt::CaseInSensitive Case insensitive
result = list.filter("bill",Qt::CaseInSensitive);
// result: ["Bill Murray", "Bill Clinton"]summary :
QStringList Class provides a list of strings .QStringList Inherited from QList < QString >. And QList equally ,QStringList Is implicitly shared . It provides fast index based access , And quick insert and delete . Passing a list of strings as a value parameter is fast and safe .QList All functions of the also apply to QStringList. for example , You can use isEmpty() To test whether the list is empty , You can call things like append()、prepend()、insert()、replace()、removeAll()、removeAt()、removeFirst() and removeOne() To modify the QStringList Function of . Besides ,QStringList Provides some convenient functions , Make it easier to handle lists of strings
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/133033.html Link to the original text :https://javaforall.cn
边栏推荐
- Transmitting and receiving antenna pattern
- MySQL character set
- 安全省油环保 骆驼AGM启停电池魅力十足
- 认识微信小程序项目的基本组成结构
- 线程池实现:信号量也可以理解成小等待队列
- Golang uses Mongo driver operation -- Query (array related)
- 炼金术(4): 程序员的心智模型
- 单细胞数据清洗的这5个步骤你会做吗?
- Does the subscription of Siyuan notes stop deleting cloud data directly?
- [AI application] detailed parameters of NVIDIA Tesla v100s-pcie-32gb
猜你喜欢

【PCL自学:PCLVisualizer】点云可视化工具PCLVisualizer

夏日的晚会

ASP. Net warehouse purchase, sales and inventory ERP management system source code ERP applet source code

Eliminate gaps around El image images

2022 PMP project management examination agile knowledge points (3)

零基础自学SQL课程 | SQL基本函数大全

Sécurité, économie de carburant et protection de l'environnement chameau
![Using two stacks to implement queues [two first in first out is first in first out]](/img/de/07297816f1a44d41389bb45d012c80.png)
Using two stacks to implement queues [two first in first out is first in first out]

Zero foundation self-study SQL course | complete collection of SQL basic functions
Does the subscription of Siyuan notes stop deleting cloud data directly?
随机推荐
赛尔笔记|视频文本预训练简述
一文剖析C语言函数
Is not null and in SQL= Difference between null
An analysis of C language functions
RNA-seq入门实战(一):上游数据下载、格式转化和质控清洗
Transmitting and receiving antenna pattern
炼金术(6): 可迭代的模型和用例
mysql读写分离配置
[PCL self study: pclvisualizer] point cloud visualization tool pclvisualizer
Zero foundation self-study SQL course | complete collection of date functions in SQL
翻译(4): 文本自动完成的匹配规则
VirtualBox extended dynamic disk size pit
超纲练习题不超纲
Detailed explanation of MATLAB axis coordinate axis related settings
Webserver flow chart -- understand the calling relationship between webserver modules
现代编程语言:Rust (铁锈,一文掌握钢铁是怎样生锈的)
What are the ways to combine the points system with marketing activities
炼金术(2): 为什么要用issue管理软件
It supports deleting and updating the priority queue of any node
[PCL self study: Segmentation3] PCL based point cloud segmentation: region growth segmentation