#include <QtCore/QCoreApplication>#include <QFile>#include <QByteArray>#include <QThread>#include <QByteArray>#include <QDebug>class Thread : public QThread{ Q_OBJECT public : Thread(QObject *parent = 0):QThread(parent){} void run() { while (true) { check_queue(); usleep(50); } } void addQueue(QByteArray * data) { listByte << data; } private : QList<QByteArray *> listByte; void check_queue() { if (!listByte.isEmpty()) { if (listByte[0] != NULL) { delete listByte[0]; listByte[0] = NULL; } } }};int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); int indexFile = 1; QString filePath = "D:/MyDocument/Picture/camera/%1.jpg"; Thread *thread = new Thread(); thread->start(); while (true) { qDebug() << "open file" << filePath.arg(indexFile); QFile file(filePath.arg(indexFile)); file.open(QIODevice::ReadOnly); QByteArray *data = new QByteArray(file.readAll()); thread->addQueue(data); file.close(); ++indexFile; if (indexFile == 10) indexFile = 1; } return 0;}#include "main.moc"
C++ (Qt)Thread t;...t.addQueue(b);