#include "messagequeue.h" #include "qdebug.h" #include #include void MessageQueue::processQueue() { if (isProcessing || messageQueue.isEmpty()) { return; } isProcessing = true; QString currentMessage = messageQueue.dequeue(); QVariant messageBoxPointX = this->messageBoxPointX; QVariant messageBoxPointY = this->messageBoxPointY; QVariant messageTitle = this->messageTitle; qDebug() << "currentMessage" << currentMessage; // 在主线程中显示消息框 QMetaObject::invokeMethod( QApplication::instance(), [this, currentMessage, messageBoxPointX, messageBoxPointY, messageTitle]() { bool isokX = false; bool isokY = false; int x = messageBoxPointX.toInt(&isokX); int y = messageBoxPointY.toInt(&isokY); qDebug() << x << y << isokX << isokY; QMessageBox *messageBox = new QMessageBox; if (isokX && isokY) { messageBox->move(x, y); } QString title = messageTitle.toString(); if (title.isEmpty()) { title = tr("Tips"); } messageBox->setWindowModality(Qt::NonModal); messageBox->setText(currentMessage); messageBox->setWindowTitle(title); connect(messageBox, &QMessageBox::finished, this, &MessageQueue::onMessageBoxClosed); messageBox->show(); }, Qt::QueuedConnection); }