当前位置:网站首页>Detailed explanation of QT qstring
Detailed explanation of QT qstring
2022-07-28 16:25:00 【icewst】
List of articles
Some descriptions :
QString Class is Qt Class used to represent strings in , Realize in QtCore In the shared library .QString Class has the following characteristics in implementation .
- String adoption Unicode Internal encoding , Words that can express most languages in the world ; The string is stored with a reference count , When one QString Object is copied as another
- QString Object time , They actually point to the same storage space , Just add a reference count ; use “ Copy on demand ” Technology , When pointing to multiple of the same storage space
- QString When one of the objects is to be modified , Will actually copy a new string and modify it .
1. establish
QString str1 = "Welcome";
// The following is wrong !!! After initialization , To add !
QString str2 = "Welcome"+" OK";
// correct
QString str3="Welcome";
str3=str3+"Hello";
2. Connection splicing
QString abc="sss";
abc="xxx"+abc+"123"+abc;
3. Compare
QString str="hello" ;
if(str =="hello")
{
qDebug("xiangtong");
}
The result is xiangtong
// return int Type values , be equal to 0 It means the same , It's not equal to 0 Different
//Qt::CaseInsensitive This type , Indicates case insensitive Qt::CaseSensitive Indicates case sensitivity
QString str="Hello" ;
if(str.compare("hello",Qt::CaseInsensitive)==0)
{
qDebug("xiangtong");
}
The result is xiangtong
4. Is it an empty string
QString str;
if(str==NULL){
qDebug("kong");
}
if(str==""){
qDebug("kong");
}
QString str1="";
if(str1==""){
qDebug("kong");
}
The results of all three are kong
5. Convert case
QString str="Hello" ;
str=str.toLower();
qDebug(str.toLatin1()); // The output here is : hello
str=str.toUpper();
qDebug(str.toLatin1()); // The output here is : HELLO
6. To obtain the length of the
QString str="Hello" ;
int len=str.length();
qDebug("%d",len); // The output here is :5
7. Remove space
//trimmed Only remove the spaces at the beginning and end
QString str=" He llo " ;
str=str.trimmed();
qDebug(str.toLatin1()); // Output results :He llo
// by this means , To remove all spaces
QString str1=" He llo " ;
str1=str1.remove(QRegExp("\\s"));
qDebug(str1.toLatin1());// Output results :Hello
8. Get substring
//mid The first parameter of position Is the starting position of the substring
//mid The second parameter of n Is the number of strings
// If n by -1, It means to the end of the original string .
QString str="Hello" ;
QString str1=str.mid(0,2);
qDebug(str1.toLatin1());// The output is :He
9. Find string
// Default comparison , Case sensitive
QString str="Hello" ;
if(str.contains("hel")){
qDebug("yes");
}else{
qDebug("no");
}
// The output is :no
// Case insensitive comparison
QString str="Hello" ;
if(str.contains("hel",Qt::CaseInsensitive)){
qDebug("yes");
}
// The output is :yes CaseInsensitive Indicates case insensitive
10. Replace string
QString str="Hello" ;
str=str.replace("llo","xxx");
qDebug(str.toLatin1()); // The output is :Hexxx
11. and char* Conversion between
//char* turn QString
char charArry[] = "hello";
char* ch = charArry;
QString str = Qstring::fromUtf8(ch);
//QString turn char*, First to string, Avoid miscoding in Chinese
QString filename="he Chinese llo";
std::string str = filename.toStdString();
const char* ch = str.c_str();
qDebug(ch);
//QString turn char*
QString str= "he Chinese llo";
char* ch ;
QByteArray ba = str.toUtf8();// This sentence avoids Chinese garbled , This sentence and the following sentence cannot be written together
ch=ba.data();
qDebug(ch);
12. Conversion between string and numeric value
QString str="20";
int strInt=str.toInt();
int num=100;
QString str= QString::number(num);
matters needing attention :
- When comparing Chinese
- Chinese do and char* When switching between
边栏推荐
- Numpy ndarray learning < I > Foundation
- Redis series 4: sentinel (sentinel mode) with high availability
- The deep displacement monitoring system wk813 is used to measure the deep displacement of slopes, dams, embankments, railways and building foundation pit excavation
- 【Multisim仿真】LM339过零电路仿真
- 2021 肯特面试题1
- 远距离串口服务器( 适配器)UART/I2C/1-Wire/SPI PS304常见问题及注意事项
- Image semantic segmentation practice: tensorflow deeplobv3+ train your own dataset
- js 链表 02
- 我在上海偶遇数字凤凰#坐标徐汇美罗城
- LwIP development | realize TCP server through socket
猜你喜欢

激光测距仪非接触式地表裂缝监测仪

头条文章_signature

JS queue

The epidemic dividend disappeared, and the "home fitness" foam dissipated

2-channel Di high-speed pulse counter, 1-channel encoder to Modbus TCP wired wireless module ibf161

Practical development tutorial of software problem repair tracking system (Part 1)

Ask if you don't understand, and quickly become an advanced player of container service!

One channel encoder, two channels Di speed measurement, RS485 serial port connected to one channel do alarm module ibf151

2021 Kent interview question 2

Image semantic segmentation practice: tensorflow deeplobv3+ train your own dataset
随机推荐
解决电脑恶意广告弹窗的思路
Thoughts on solving the pop-up of malicious computer advertisements
振弦采集模块测量振弦传感器的流程步骤?
Stm32cube infrared remote control: input capture
LabVIEW LINX Toolkit控制Arduino设备(拓展篇—1)
Darknet training yolov4 record
远距离串口服务器( 适配器)UART/I2C/1-Wire/SPI PS304常见问题及注意事项
射频模块无线收发RF63U芯片应用数据传输和基建网络
Zhengda cup hacker marathon data analysis competition
远距离串口服务器( 适配器)UART 转 1-Wire 应用
Remember the common JS methods of projects
JS array (summary)
Ffmpeg get the first frame
高精度绝对角度传感器应用高速度角度监测
2021 Kent interview question 1
2021 Yahong pen test question 2
跳表的实现
VM501开发套件开发版单振弦式传感器采集模块岩土工程监测
el-input限制只能输入规定的数
NTC, PT100 thermal resistance to 4-20mA temperature signal converter