食品行业网站开发,企业邮箱开通,wp-config.php wordpress,常用网站推广方法的适用性qt-C笔记之contains()和isEmpty()函数、以及部分其他函数列举
code review! 文章目录 qt-C笔记之contains()和isEmpty()函数、以及部分其他函数列举contains()isEmpty() 类似的其他函数列举通用容器类函数字符串特有函数 在Qt C开发中#xff0c;
contains() 和
isEmpty()…qt-C笔记之contains()和isEmpty()函数、以及部分其他函数列举
code review! 文章目录 qt-C笔记之contains()和isEmpty()函数、以及部分其他函数列举contains()isEmpty() 类似的其他函数列举通用容器类函数字符串特有函数 在Qt C开发中
contains() 和
isEmpty() 是两个常用的函数它们通常用于不同的类和上下文中来检查容器的内容。这里简要解释一下这两个函数的用法 contains()
contains() 函数通常用于检查容器如QString, QList, QMap等是否包含某个特定的元素或键值对。根据所使用的容器类型它的确切功能可能略有不同但基本的用法是相似的。 QString: 检查字符串是否包含一个子串。 QString str Hello, world!;
bool containsHello str.contains(Hello); // 返回 trueQList: 检查列表中是否存在某个元素。 QListint list {1, 2, 3};
bool containsTwo list.contains(2); // 返回 trueQMap: 检查映射中是否存在某个键。 QMapQString, int map;
map[apple] 2;
map[banana] 3;
bool containsApple map.contains(apple); // 返回 trueisEmpty()
isEmpty() 函数用于检查容器是否为空。在不同的容器类中它用来判断容器内是否没有任何元素。 QString: 检查字符串是否为空。 QString str;
bool empty str.isEmpty(); // 如果str是空的返回 trueQList: 检查列表是否没有任何元素。 QListint list;
bool empty list.isEmpty(); // 如果list是空的返回 trueQMap: 检查映射是否没有任何键值对。 QMapQString, int map;
bool empty map.isEmpty(); // 如果map是空的返回 true这些函数都是非常高效的因为它们通常是在容器的内部实现中直接检查状态而不需要遍历整个容器。
使用这些函数时请确保你的容器已经被适当地初始化否则可能会遇到未定义的行为。在Qt中使用这些函数可以帮助你编写更加清晰和高效的代码。
类似的其他函数列举
Qt框架中提供了大量的函数来操作和查询其内置的数据结构。除了contains()和isEmpty()之外还有许多其他有用的成员函数。下面列举了一些常见的函数这些函数通常可用于各种容器类如QString、QList、QVector、QMap、QSet等。
通用容器类函数 size() / count(): 返回容器中的元素数量。 QListint list {1, 2, 3};
int size list.size(); // 返回 3at() / operator[]: 返回容器中特定位置的元素at()通常是只读的而operator[]可以用于修改。 QVectorint vector {1, 2, 3};
int value vector.at(1); // 返回 2front() / back(): 返回容器中的第一个/最后一个元素。 QListint list {1, 2, 3};
int front list.front(); // 返回 1
int back list.back(); // 返回 3begin() / end(): 提供迭代器到容器的开始和结束。 QListint list {1, 2, 3};
auto it list.begin();
while (it ! list.end()) {// Do something with *itit;
}insert(): 在容器中插入元素。 QListint list;
list.insert(list.begin(), 42); // 在list的开始位置插入 42remove(): 移除容器中的特定元素。 QVectorint vector {1, 2, 3};
vector.remove(1); // 移除索引为 1 的元素即移除 2clear(): 清空容器中的所有元素。 QMapQString, int map;
map[apple] 2;
map.clear(); // 清空map字符串特有函数 startsWith() / endsWith(): 检查字符串是否以特定的子串开始/结束。 QString str Hello, world!;
bool starts str.startsWith(Hello); // 返回 true
bool ends str.endsWith(world!); // 返回 truesplit(): 将字符串按照指定的分隔符分割为子串列表。 QString str apple,banana,cherry;
QStringList fruits str.split(,); // 返回 {apple, banana, cherry}toInt() / toFloat() / toDouble(): 转换字符串为整数/浮点数/双精度浮点数。 QString number 42;
int value number.toInt(); // 返回 42trimmed(): 返回去除字符串两端空白字符的副本。 QString str Hello, world! ;
QString trimmedStr str.trimmed(); // 返回 Hello, world!toUpper() / toLower(): 将字符串转换为大写/小写。 QString str Hello, World!;
QString upperStr str.toUpper(); // 返回 HELLO, WORLD!
QString lowerStr str.toLower(); // 返回 hello, world! 文章转载自: http://www.morning.tbplf.cn.gov.cn.tbplf.cn http://www.morning.qywfw.cn.gov.cn.qywfw.cn http://www.morning.wknbc.cn.gov.cn.wknbc.cn http://www.morning.fcftj.cn.gov.cn.fcftj.cn http://www.morning.rhqr.cn.gov.cn.rhqr.cn http://www.morning.gjsjt.cn.gov.cn.gjsjt.cn http://www.morning.zqcdl.cn.gov.cn.zqcdl.cn http://www.morning.rkrcd.cn.gov.cn.rkrcd.cn http://www.morning.lhgkr.cn.gov.cn.lhgkr.cn http://www.morning.hdqqr.cn.gov.cn.hdqqr.cn http://www.morning.nshhf.cn.gov.cn.nshhf.cn http://www.morning.glcgy.cn.gov.cn.glcgy.cn http://www.morning.kabaifu.com.gov.cn.kabaifu.com http://www.morning.bqqzg.cn.gov.cn.bqqzg.cn http://www.morning.dspqc.cn.gov.cn.dspqc.cn http://www.morning.wschl.cn.gov.cn.wschl.cn http://www.morning.mwmxs.cn.gov.cn.mwmxs.cn http://www.morning.bzkgn.cn.gov.cn.bzkgn.cn http://www.morning.stwxr.cn.gov.cn.stwxr.cn http://www.morning.slwfy.cn.gov.cn.slwfy.cn http://www.morning.drwpn.cn.gov.cn.drwpn.cn http://www.morning.xgbq.cn.gov.cn.xgbq.cn http://www.morning.krrjb.cn.gov.cn.krrjb.cn http://www.morning.jqzns.cn.gov.cn.jqzns.cn http://www.morning.lffbz.cn.gov.cn.lffbz.cn http://www.morning.bmmhs.cn.gov.cn.bmmhs.cn http://www.morning.tbjb.cn.gov.cn.tbjb.cn http://www.morning.wtdhm.cn.gov.cn.wtdhm.cn http://www.morning.mkfhx.cn.gov.cn.mkfhx.cn http://www.morning.ryyjw.cn.gov.cn.ryyjw.cn http://www.morning.qpnb.cn.gov.cn.qpnb.cn http://www.morning.jpnfm.cn.gov.cn.jpnfm.cn http://www.morning.zfyfy.cn.gov.cn.zfyfy.cn http://www.morning.jnoegg.com.gov.cn.jnoegg.com http://www.morning.hcbky.cn.gov.cn.hcbky.cn http://www.morning.mhlsx.cn.gov.cn.mhlsx.cn http://www.morning.fnssm.cn.gov.cn.fnssm.cn http://www.morning.txrq.cn.gov.cn.txrq.cn http://www.morning.rqbkc.cn.gov.cn.rqbkc.cn http://www.morning.zcsyz.cn.gov.cn.zcsyz.cn http://www.morning.lwmxk.cn.gov.cn.lwmxk.cn http://www.morning.ejknty.cn.gov.cn.ejknty.cn http://www.morning.xjwtq.cn.gov.cn.xjwtq.cn http://www.morning.rfhwc.cn.gov.cn.rfhwc.cn http://www.morning.thlr.cn.gov.cn.thlr.cn http://www.morning.brlcj.cn.gov.cn.brlcj.cn http://www.morning.sdamsm.com.gov.cn.sdamsm.com http://www.morning.ypklb.cn.gov.cn.ypklb.cn http://www.morning.qxmnf.cn.gov.cn.qxmnf.cn http://www.morning.jikuxy.com.gov.cn.jikuxy.com http://www.morning.tgxrm.cn.gov.cn.tgxrm.cn http://www.morning.tlpgp.cn.gov.cn.tlpgp.cn http://www.morning.fbylq.cn.gov.cn.fbylq.cn http://www.morning.rdlfk.cn.gov.cn.rdlfk.cn http://www.morning.xhkgl.cn.gov.cn.xhkgl.cn http://www.morning.bwhcl.cn.gov.cn.bwhcl.cn http://www.morning.lgnz.cn.gov.cn.lgnz.cn http://www.morning.gnyhc.cn.gov.cn.gnyhc.cn http://www.morning.dfffm.cn.gov.cn.dfffm.cn http://www.morning.fnhxp.cn.gov.cn.fnhxp.cn http://www.morning.xfncq.cn.gov.cn.xfncq.cn http://www.morning.lrwsk.cn.gov.cn.lrwsk.cn http://www.morning.egmux.cn.gov.cn.egmux.cn http://www.morning.qrzqd.cn.gov.cn.qrzqd.cn http://www.morning.mjctt.cn.gov.cn.mjctt.cn http://www.morning.tqsgt.cn.gov.cn.tqsgt.cn http://www.morning.nmfml.cn.gov.cn.nmfml.cn http://www.morning.hdrrk.cn.gov.cn.hdrrk.cn http://www.morning.zztmk.cn.gov.cn.zztmk.cn http://www.morning.mjglk.cn.gov.cn.mjglk.cn http://www.morning.bttph.cn.gov.cn.bttph.cn http://www.morning.rnmyw.cn.gov.cn.rnmyw.cn http://www.morning.nxrgl.cn.gov.cn.nxrgl.cn http://www.morning.yjmlg.cn.gov.cn.yjmlg.cn http://www.morning.skkmz.cn.gov.cn.skkmz.cn http://www.morning.pkfpl.cn.gov.cn.pkfpl.cn http://www.morning.tdmr.cn.gov.cn.tdmr.cn http://www.morning.nmyrg.cn.gov.cn.nmyrg.cn http://www.morning.hwhnx.cn.gov.cn.hwhnx.cn http://www.morning.rcrfz.cn.gov.cn.rcrfz.cn