当前位置:网站首页>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;
}
边栏推荐
- [graduation season] graduation is the new beginning of your life journey. Are you ready
- 通过uview让tabbar根据权限显示相应数量的tabbar
- Process termination (have you really learned recursion? Test your recursion Foundation)
- 正斜杠反斜杠的由来
- postgreSQL在windows系统遇到权限否认(permission denied)
- 延时队列`DelayQueue`
- sql sever列名或所提供值的数目与表定义不匹配
- js中判断奇偶的函数,求圆面积的函数
- Error in idea connection database
- 一個人管理1000臺服務器?這款自動化運維工具一定要掌握
猜你喜欢
![[Kevin's third play in a row] is rust really slower than C? Further analyze queen micro assessment](/img/ac/44e0ecd04fbea5efd39d2cc75dea59.jpg)
[Kevin's third play in a row] is rust really slower than C? Further analyze queen micro assessment

How to write controller layer code gracefully?

IDEA连接数据库报错

如何优雅的写 Controller 层代码?

Memory barrier store buffer, invalid queue

用XGBoost迭代读取数据集
![Speech signal processing - concept (II): amplitude spectrum (STFT spectrum), Mel spectrum [the deep learning of speech mainly uses amplitude spectrum and Mel spectrum] [extracted with librosa or torch](/img/b3/6c8d9fc66e2a4dbdc0dd40179266d3.png)
Speech signal processing - concept (II): amplitude spectrum (STFT spectrum), Mel spectrum [the deep learning of speech mainly uses amplitude spectrum and Mel spectrum] [extracted with librosa or torch
![[compilation principles] review outline of compilation principles of Shandong University](/img/a6/b522a728ff21085411e7452f95872a.png)
[compilation principles] review outline of compilation principles of Shandong University

正斜杠反斜杠的由来

使用 Blackbox Exporter 测试网络连通性
随机推荐
[openairinterface5g] rrcsetupcomplete for RRC NR resolution
Cookie加密6
Bean copy details
How to write controller layer code gracefully?
磁选机是什么?
Interviewer: please introduce cache penetration, cache null value, cache avalanche and cache breakdown, which are easy to understand
JDBC读取Mysql数据列表
【编译原理】山东大学编译原理复习提纲
用XGBoost迭代读取数据集
manim 数学引擎
数据库系统工程师对口专业有哪些?
JDBC parameterized query example
多表联查--07--- Hash join
Construction of defense system for attack and defense exercises part II common strategies for responding to attacks
R 语言 基于关联规则与聚类分析的消费行为统计
webscoket 数据库监听
Yolov6's fast and accurate target detection framework is open source
Custom palette for ggplot2
大学数据库mysql
OpenCV怎么下载?OpenCV下载后怎么配置?