首页 > 其他 > 详细

Qt在使用过程中的小总结

时间:2018-06-07 23:32:15      阅读:177      评论:0      收藏:0      [点我收藏+]

一、QT int转QString,并补0

int a = 3;
QString str = QString("%1").arg(a, 4, 10, QLatin1Char(0));
//str值为0003

二、QT int转16进制,并补0

int num = 5;
QString res = QString("%1").arg(num,  4, 16, QLatin1Char(0));
//res值为0005

 三、QT之日期时间

  获取系统当前时间并设置显示格式

QDateTime time = QDateTime::currentDateTime();
QString currTime = time.toString("yyyy-MM-dd hh:mm::ss ddd");
//currTime    2018-06-07 22:36::07 周四    

 四、查询字符串数据

  ① 函数QString::startsWith()判断一个字符串是否以某个字符串开头。

   此函数有两个参数:第一个参数指定了一个字符串,第二个参数指定是否大小写敏感(默认情况下是大小写敏感的)

QString str = "Welcome to you";
str.startWith("Welcome ", Qt::CaseSensitive);
str.startWith("you ", Qt::CaseSensitive);

  ② 函数QString::endWith()类似于QString::startsWith(),此函数判断一个字符串是否某个字符串结尾、

  ③ 函数QString::contains()判断一个字符串是否出现过

QString str = "Welcome to you";
str.contains("Welcome ", Qt::CaseSensitive);//返回true

 

Qt在使用过程中的小总结

原文:https://www.cnblogs.com/jiangson/p/9153142.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!