当前位置:网站首页>2. QT components used in the project
2. QT components used in the project
2022-06-27 07:31:00 【Endless character】
Catalog
Preface
- Before starting the development project , We need to be aware of the QT Component to introduce some usage
One 、QString and QDebug
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QString>
#include <QDebug>
int main(int argc, char *argv[])
{
//QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//QGuiApplication app(argc, argv);
//QQmlApplicationEngine engine;
//engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
//if (engine.rootObjects().isEmpty())
// return -1;
//return app.exec();
QString str = "C:/";
QString str2 = "D:\\";
qDebug() << str << endl;
qDebug() << str2 << endl;
// Splicing
str += "muying/";
str2.append("muying/");
qDebug() << str << endl;
qDebug() << str2 << endl;
// Empty
str.clear();
// String search
int pos = str2.indexOf("\\");
pos = str.indexOf("X");
//QStringLiteral yes QString The macro , Use this macro to calculate the length of the string
// Intercepting string ,param1= Intercept start position ,param2= Intercept length
str2 = str2.mid(pos + 1, QStringLiteral("muying").length());
qDebug() << str << endl;
qDebug() << str2 << endl;
// Numbers -> character string : Transformation method 1
str = QString::number(3.14);
// Numbers -> character string : Transformation method 2
str.setNum(34);
// character string -> Numbers
QString str3 = "123";
int i = str3.toInt();
qDebug("The value of str is: %s", qPrintable(str3));//qPrintable macro , Convert to const char*
qDebug("The value of i is: %d", i);
str3 = "abc";
i = str3.toInt(); // Although it cannot be converted , But there is no error ,i=0
qDebug("The value of str is: %s", qPrintable(str3));
qDebug("The value of i is: %d", i);
return 0;
}
Two 、QScopedPointer Intelligent pointer
- A simple test : Adding method blocks is to create method blocks , Release from stack
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QString>
#include <QDebug>
class SPA
{
public:
SPA()
{
qDebug() << "SPA::SPA()" << endl;
}
~SPA()
{
qDebug() << "SPA::~SPA()" << endl;
}
};
int main(int argc, char *argv[])
{
// QScopedPointer
{
QScopedPointer<int> i(new int(3));
QScopedPointer<SPA> spA(new SPA);
}
return 0;
}

- reset Use
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QString>
#include <QDebug>
class SPA
{
public:
SPA()
{
qDebug() << "SPA::SPA()" << endl;
}
~SPA()
{
qDebug() << "SPA::~SPA()" << endl;
}
void Print()
{
qDebug() << "SPA::Print()" << endl;
}
};
int main(int argc, char *argv[])
{
// QScopedPointer
{
QScopedPointer<int> i2(new int(3));
qDebug("The value of i2 is: %d", *i2);//3
i2.reset(new int(4));
qDebug("The value of i2 is: %d", *i2);//4
QScopedPointer<SPA> spA(new SPA);
spA->Print();
QScopedArrayPointer<SPA> spArr(new SPA[10]);// Array version
}
return 0;
}
3、 ... and 、QThread Multithreading
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QString>
#include <QDebug>
#include <QThread>
class MyThread :public QThread
{
public:
MyThread()
{
isStop = false;
}
void CloseThread()
{
isStop = true;
}
void run()
{
while (true)
{
if (isStop) {
return; }
//tr Internationalize and standardize strings
qDebug() << tr("MyThread id is: ") << QThread::currentThreadId();
sleep(1);
}
}
private:
bool isStop;
};
int main(int argc, char *argv[])
{
// Implement multithreading
MyThread thread;
thread.start();
while (true)
{
;
}
thread.CloseThread();
return 0;
}
边栏推荐
- pytorch Default process group is not initialized
- 什么是浮选机?
- R language calculates Spearman correlation coefficient in parallel to speed up the construction of co occurrence network
- 【软件工程】山东大学软件工程复习提纲
- 延时队列`DelayQueue`
- 【Kevin三连弹之三】Rust真的比C慢吗?进一步分析queen微测评
- Coggle 30 Days of ML 7月竞赛学习
- 将通讯录功能设置为数据库维护,增加用户名和密码
- VNC Viewer方式的远程连接树莓派
- poi导出excle
猜你喜欢

cookie加密7 fidder分析阶段

Goodbye, agile Scrum

Yarn create vite reports an error 'd:\program' which is neither an internal or external command nor a runnable program or batch file

DMU software syntax highlighting VIM setting -- Learning Notes 6

Coggle 30 Days of ML 7月竞赛学习

再见了,敏捷Scrum

进程终止(你真的学会递归了吗?考验你的递归基础)

MySQL
![[compilation principles] review outline of compilation principles of Shandong University](/img/a6/b522a728ff21085411e7452f95872a.png)
[compilation principles] review outline of compilation principles of Shandong University

Solve the problem of win10 wsl2 IP change
随机推荐
JDBC事务提交事例
Goodbye, agile Scrum
语音信号处理-概念(一):时谱图(横轴:时间;纵轴:幅值)、频谱图(横轴:频率;纵轴:幅值)--傅里叶变换-->时频谱图【横轴:时间;纵轴:频率;颜色深浅:幅值】
Win10 remote connection to ECS
语音信号处理-概念(二):幅度谱(短时傅里叶变换谱/STFT spectrum)、梅尔谱(Mel spectrum)【语音的深度学习主要用幅度谱、梅尔谱】【用librosa或torchaudio提取】
Rust中的Pin详解
JDBC parameterized query example
pytorch Default process group is not initialized
程序人生 - 程序员三十五岁瓶颈你怎么看?
突破从0到1后,鲜花电商2.0时代怎么走?
使用 Blackbox Exporter 测试网络连通性
JDBC reads MySQL data list
Bean copy details
再见了,敏捷Scrum
Apifox learning
JDBC读取Mysql数据列表
File 与 MultipartFile概述
延时队列`DelayQueue`
R 语言并行计算 spearman 相关系数,加快共现网络(co- occurrence network)构建速度
Solve the problem of win10 wsl2 IP change