当前位置:网站首页>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
边栏推荐
- SQL reported an unusual error, which confused the new interns
- Instructions for vivado FFT IP
- mysql数据库旅游管理系统_JSP+MySQL基于ssm的旅游管理系统[通俗易懂]
- 炼金术(8): 开发和发布的并行
- ASP.NET仓库进销存ERP管理系统源码 ERP小程序源码
- golang使用mongo-driver操作——查(基础)
- 本地可视化工具连接阿里云centOS服务器的redis
- At the beginning of reading English literature, I would like to ask you how you should read it in the first place?
- [AI application] detailed parameters of Jetson Xavier nx
- MySQL read / write separation configuration
猜你喜欢

技术的极限(11): 有趣的编程
![[digital ic/fpga] detect the position of the last matching sequence](/img/67/a1b575aa9b63892ed585d39e615c58.png)
[digital ic/fpga] detect the position of the last matching sequence
![计数质数[枚举 -> 空间换时间]](/img/11/c52e1dfce8e35307c848d12ccc6454.png)
计数质数[枚举 -> 空间换时间]

Storage structure of graph
![[读书摘要] 学校的英文阅读教学错在哪里?--经验主义和认知科学的PK](/img/7b/8b3619d7726fdaa58da46b0c8451a4.png)
[读书摘要] 学校的英文阅读教学错在哪里?--经验主义和认知科学的PK

2022 PMP project management examination agile knowledge points (3)
![[idea] idea formatting code skills](/img/06/38079517e901bc48dc4ca0f8cc63fe.jpg)
[idea] idea formatting code skills

Sentinel

现代编程语言:Rust (铁锈,一文掌握钢铁是怎样生锈的)

安全省油环保 骆驼AGM启停电池魅力十足
随机推荐
内网IP和公网IP的区别及作用
CRTMP视频直播服务器部署及测试
现代编程语言:zig
表单form 和 表单元素(input、select、textarea等)
[PCL self study: pclplotter] pclplotter draws data analysis chart
[PCL self study: pclvisualizer] point cloud visualization tool pclvisualizer
Character interception triplets of data warehouse: substrb, substr, substring
计数质数[枚举 -> 空间换时间]
翻译(5): 技术债务墻:一种让技术债务可见并可协商的方法
Cornernet understands from simple to profound
【PCL自学:PCLPlotter】PCLPlotter绘制数据分析图
apipost脚本使用讲解一~全局变量
吴恩达《机器学习》课程总结(14)_降维
SCU|通过深度强化学习进行微型游泳机器人的步态切换和目标导航
SQL中IS NOT NULL与!=NULL的区别
[try to hack] kill evaluation
TIME_WAIT过多的解决办法
Transmitting and receiving antenna pattern
积分体系和营销活动结合在一起有哪些玩法
Is the securities registration account safe? Is there any risk?