当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

File and multipartfile overview

(已解决) MINet 进行测试时报错如下 raise NotImplementedError

IDEA连接数据库报错

Memory barrier store buffer, invalid queue

Remote connection raspberry pie in VNC Viewer Mode

Stream常用操作以及原理探索

Error in idea connection database

语音信号处理-概念(二):幅度谱(短时傅里叶变换谱/STFT spectrum)、梅尔谱(Mel spectrum)【语音的深度学习主要用幅度谱、梅尔谱】【用librosa或torchaudio提取】

使用 Blackbox Exporter 测试网络连通性

js输出1-100之间所有的质数并求总个数
随机推荐
manim 数学引擎
攻防演习防御体系构建之第二篇之应对攻击的常用策略
JDBC operation MySQL example
Park and unpark in unsafe
1-4 decimal representation and conversion
postgreSQL在windows系统遇到权限否认(permission denied)
mysql关于自增和不能为空
Jupiter notebook file directory
Error in idea connection database
Bean拷贝详解
R 语言Analyzing wine data
poi导出excle
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
内存屏障今生之Store Buffer, Invalid Queue
R 中的 RNA-Seq 数据分析 - 调查数据中的差异表达基因!
Process termination (have you really learned recursion? Test your recursion Foundation)
数据库系统工程师对口专业有哪些?
window右键管理
log4j:WARN No such property [zipPermission] in org.apache.log4j.RollingFileAppender.