当前位置:网站首页>QT qstringlist usage
QT qstringlist usage
2022-06-30 20:16:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
QStringList Class provides a list of strings from QList <QString> inherited , It provides fast index based access as well as fast insertion and removal Its member functions are used to manipulate this string list, such as append(),insert(), replace(), removeAll(), removeAt(), removeFirst(), removeLast(), and removeOne() etc. 1. Add string Can pass append(), Or use <<, Such as QStringList fonts; fonts << “Arial” << “Helvetica” << “Times” << “Courier”; // fonts:[ “Arial” ,”Helvetica”, “Times” , “Courier”] 2. Merge strings using join( ) 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 there is QString::SkipEmptyParts, Empty items will not appear in the result . By default , Blank items are reserved 4. 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 . 5. Replace replaceInStrings() QStringList files; files << “$QTDIR/src/moc/moc.y” << “$QTDIR/src/moc/moc.l” << “$QTDIR/include/qconfig.h”; files.replaceInStrings(“$QTDIR”, “/usr/lib/qt”); // files: [ “/usr/lib/qt/src/moc/moc.y”, …] 6. 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”]
7. Traverse
QList<QString>::Iterator it = user.begin(),itend = user.end(); int i = 0; for (;it != itend; it++,i++){ if (*it == pFindLine->text()){// find , Highlight QModelIndex index = model->index(i); m_pTabList->setCurrentIndex(index); break; } }
Publisher : Full stack programmer stack length , Reprint Please indicate the source :https://javaforall.cn/132117.html Link to the original text :https://javaforall.cn
边栏推荐
- Web主机iptables防火墙安全脚本
- 计网 | 【五 传输层、六 应用层】知识点及例题
- 1045 error occurred in MySQL login. Modification method [easy to understand]
- Audio and video architecture construction in the super video era | science and Intel jointly launched the second season of "architect growth plan"
- Introduction to neural network (Part 1)
- 企业中台规划和IT架构微服务转型
- discuz 论坛提速之删除data/log下的xxx.php文件
- 【450. 删除二叉搜索树中的节点】
- 8 - function
- GeoServer安装
猜你喜欢
随机推荐
1045 error occurred in MySQL login. Modification method [easy to understand]
The prospectus of pelt medical was "invalid" for the second time in the Hong Kong stock exchange, and the listing plan was substantially delayed
MySQL billing Statistics (Part 1): MySQL installation and client dbeaver connection
杰理之触摸按键识别流程【篇】
S7-1500 PLC之间进行TCP通信的具体方法和步骤详解(图文)
广州股票开户选择手机办理安全吗?
以全栈全功能解决方案,应对多样工具复杂环境DevOps落地难题
项目经理是领导吗?可以批评指责成员吗?
Jerry's touch key recognition process [chapter]
Data intelligence - dtcc2022! China database technology conference is about to open
SecureCRTPortable的安装和使用(图文详解)
线下门店为什么要做新零售?
Qt:qaxobject operation Excel
Spark - 一文搞懂 Partitioner
Exness: liquidity series - liquidity cleaning and reversal, decision interval
Django上传excel表格并将数据写入数据库的详细步骤
CADD course learning (2) -- target crystal structure information
Redis ziplist 压缩列表的源码解析
Idle fish is hard to turn over
“更福特、更中国”拨云见日,长安福特王牌产品订单过万