前言
QT编译问题整理
一、按钮绑定
#ifdef Q_OS_MACX
QgsAbout::QgsAbout( QWidget *parent )
: QgsOptionsDialogBase( "about", parent, Qt::WindowSystemMenuHint ) // Modeless dialog with close button only
#else
QgsAbout::QgsAbout( QWidget * parent )
: QgsOptionsDialogBase( QStringLiteral( "about" ), parent ) // Normal dialog in non Mac-OS
#endif
{
setupUi( this );
connect( btnQgisUser, &QPushButton::clicked, this, &QgsAbout::btnQgisUser_clicked );
connect( btnQgisHome, &QPushButton::clicked, this, &QgsAbout::btnQgisHome_clicked );
initOptionsBase( true, QStringLiteral( "%1 - %2 Bit" ).arg( windowTitle() ).arg( QSysInfo::WordSize ) );
init();
}
二、QString保留位数
如题:比如1,我想转成 “001”。
有两种方法:
方法一:
int i=1;
QString b=QString(“%1”).arg(i, 3, 10, QChar(‘0’));
其中3表示需要保留3位数字,10是10进制,后面是以0补齐的意思。
方法二:
int cmd=1;QString str=QString::number(cmd).sprintf(“%03d”,cmd);
作者:zxl_1996
来源:CSDN
原文:https://blog.csdn.net/zxl_1996/article/details/80077277
版权声明:本文为博主原创文章,转载请附上博文链接!
三、QString和QTdouble
QString str1 = QString::number(10.663, 'f', 3);//返回一个相当于数字n的字符串,根据指定的格式和精度进行格式化。
qDebug()<<tr("double转QString")<<str1;
QString str2 = QString::number(10.663, 'e', 3);//'e', 'E', and 'f'小数点后保留3位
qDebug()<<tr("double转QString")<<str2;
QString str3 = QString::number(10.663, 'g', 3);//'g' and 'G'保留3位有效数字
qDebug()<<tr("double转QString")<<str3;
运行结果
其他数据类型转QString比如int也是用QString::number这个函数,用的重载版本
四、QT字符串详解
添加链接描述
1.Detailed Description(详细描述)
2. Public Functions 公有的函数
2.1 类对象的构造
2.2 追加字符串(前追加prepend or push_front和后追加append or push_back)
2.3 组合字符串(arg)
2.4 字符串的裁剪(chop,truncate,resize,remove)
2.5 字符串的比较(compare,constData)
2.6 判断字符串是否存在(contains)
2.7 判断字符串出现的次数(count)
2.8 字符串的大小长度(count,size,length)
2.9 判断字符串是否以某一个子串开始(startsWith)
2.11 查找字符串获取第一次出现位置索引(indexof)
2.12 查找字符串获取最后一次出现位置索引(lastIndexof)
2.13 字符串的插入(insert,left,leftJustified,rightJustified)
2.14 字符串的分割(mid)
2.15 字符串的删除(remove)
2.16 字符串的替换(replace)
2.17 字符串的截取(section)
2.18 字符串的裁剪(fill)
2.19 字符串的简化(simplified,trimmed)
2.20 分隔字符串 (split)
2.22 字符串------>数(toDouble,toInt…)
2.23 数------>QString字符串(setNum,number)
2.24 字符串的大小写转换(toLower,toUpper)
2.25 其他(at,begin,end,isEmpty,isNull,clear)
3. 字符串的重载