【Qt-QThread-QQueue】

Qt编程指南

  • [■ QThread](#■ QThread)
    • [■ 示例](#■ 示例)
  • [■ QQueue](#■ QQueue)

■ QThread

■ 示例

cpp 复制代码
#include <QThread>
class myThread : public QThread
{
    Q_OBJECT
signals:
    downloaded(int);
public:
    myThread();
    void run()
    {
        for(int i=0;i<100; i++)
        {
            //p1->setValue(i);
            emit downloaded(i);
            QThread::sleep(2);
        }
    }
};
t2 = new myThread;
t2->start();

■ QQueue

cpp 复制代码
头文件#include<QQueue>

/*定义一个队列 <>中的类型也可以是自己定义的结构体类性*/
QQueue<uint8_t> queue;   
 
/*入队列*/
queue.enqueue(128); 

/*出队列*/
uint8_t num = queue.dequeue();   
          
/*队列判空,返回boo类型*/
queue.isEmpty();                    

/*队列元素个数,返回队列中还有多少个元素*/
queue.size();                        

/*清空队列*/
queue.clear();

cpp 复制代码

cpp 复制代码
相关推荐
用户805533698034 天前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner4 天前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz9 天前
QML Hello World 入门示例
qt
xcyxiner12 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner13 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner13 天前
DicomViewer (添加模型类)3
qt
xcyxiner14 天前
DicomViewer (目录调整) 2
qt
xcyxiner14 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR00616 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术16 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript