当前位置:网站首页>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
边栏推荐
- LabVIEW LINX Toolkit控制Arduino设备(拓展篇—1)
- 8051 series MCU firmware upgrade IAP
- 兆骑科创创新创业大赛人才引进平台,双创赛事高层次人才引进
- I can only sell the company after the capital has been "cut off" for two years
- Installation points and precautions of split angle probe
- QT QString详解
- LwIP development | socket | DNS domain name resolution
- Why do most people who learn programming go to Shenzhen and Beijing?
- JS stack
- Temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
猜你喜欢

js 链表 01

flashfxp 530 User cannot log in. ftp

The little red book of accelerating investment, "rush to medical treatment"?

2021 Kent interview question 3

High speed counter to rs485modbus RTU module ibf150

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

视频号找到金钥匙,抖音模仿后来人

RF module wireless transceiver rf63u chip application data transmission and infrastructure network

Ethernet to RS485 serial port counter WiFi module LED light controller ibf165

5 亿用户,比微信还早四年……这个运营了 15 年的 APP 即将永久停服
随机推荐
食品安全 | 这两类瓜果宜改善便秘 孕妇人群尤其建议
Automatically pack compressed backup download and delete bat script commands
Instructions for mictr01 Tester development kit (vibrating wire acquisition reader)
Numpy ndarray learning < I > Foundation
Two special functions (arrow function and method)
LwIP development | realize TCP server through socket
laravel
Writing of factorial
李宏毅《机器学习》丨5. Tips for neural network design(神经网络设计技巧)
Rust Getting Started Guide (crite Management)
Summary of for loop in JS
I came across Digital Phoenix coordinate Xuhui Meiluo city in Shanghai
兆骑科创创新创业大赛人才引进平台,双创赛事高层次人才引进
JS bidirectional linked list 01
R语言使用fs包的file_delete函数删除指定文件夹下的指定文件、举一反三、dir_delete函数、link_delete函数可以用来删除文件夹和超链接
Stm32f103c8t6 + 0.96 "I2C OLED display 3d_cube
2021 亚鸿笔试题2
Have you seen the management area decoupling architecture? Can help customers solve big problems
KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
A tour of grp:05 - GRP server streaming service end stream