#include<QGuiApplication>#include<QQmlApplicationEngine>#include<QString>#include<QDebug>classSPA{public:SPA(){qDebug()<<"SPA::SPA()"<< endl;}~SPA(){qDebug()<<"SPA::~SPA()"<< endl;}voidPrint(){qDebug()<<"SPA::Print()"<< endl;}};intmain(int argc,char*argv[]){// QScopedPointer{
QScopedPointer<int>i2(newint(3));qDebug("The value of i2 is: %d",*i2);//3
i2.reset(newint(4));qDebug("The value of i2 is: %d",*i2);//4
QScopedPointer<SPA>spA(new SPA);
spA->Print();
QScopedArrayPointer<SPA>spArr(new SPA[10]);//数组版本}return0;}
三、QThread多线程
#include<QGuiApplication>#include<QQmlApplicationEngine>#include<QString>#include<QDebug>#include<QThread>classMyThread:publicQThread{public:MyThread(){
isStop =false;}voidCloseThread(){
isStop =true;}voidrun(){while(true){if(isStop){return;}//tr将字符串做国际化标准化的处理qDebug()<<tr("MyThread id is: ")<<QThread::currentThreadId();sleep(1);}}private:bool isStop;};intmain(int argc,char*argv[]){// 实现多线程
MyThread thread;
thread.start();while(true){;}
thread.CloseThread();return0;}