| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #ifndef MESSAGEQUEUE_H
- #define MESSAGEQUEUE_H
- #include <QObject>
- #include <QQueue>
- #include <QVariant>
- #include "qdebug.h"
- class MessageQueue : public QObject
- {
- Q_OBJECT
- public:
- explicit MessageQueue(QObject *parent = nullptr)
- : QObject(parent)
- , isProcessing(false)
- {}
- // 向队列中添加消息
- void addMessage(const QString &text,
- const QVariant &messageBoxPointX,
- const QVariant &messageBoxPointY,
- const QVariant &messageTitle)
- {
- qDebug() << text << messageBoxPointX << messageBoxPointY << messageTitle;
- this->messageBoxPointX = messageBoxPointX;
- this->messageBoxPointY = messageBoxPointY;
- this->messageTitle = messageTitle;
- messageQueue.enqueue(text);
- processQueue();
- }
- private:
- QQueue<QString> messageQueue;
- bool isProcessing;
- // 处理队列中的消息
- void processQueue();
- QVariant messageBoxPointX;
- QVariant messageBoxPointY;
- QVariant messageTitle;
- private slots:
- // 当消息框关闭时,继续处理队列中的下一个消息
- void onMessageBoxClosed()
- {
- isProcessing = false;
- processQueue();
- }
- };
- #endif // MESSAGEQUEUE_H
|