25 lines
722 B
C++
25 lines
722 B
C++
#include "ASyncWindow.h"
|
|
#include <QTimer>
|
|
|
|
ASyncWindow::ASyncWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
{}
|
|
|
|
void ASyncWindow::QueueTask(TSQueue::t_Callable c)
|
|
{
|
|
m_taskQueue.add(std::move(c));
|
|
// Theoretically this needs to be only called if the queue was empty because otherwise it already would
|
|
// be busy emptying the queue. For now however I think it is safer to call it just to make sure.
|
|
QMetaObject::invokeMethod(this, "processCallableQueue", Qt::QueuedConnection); // queues on main thread
|
|
}
|
|
|
|
void ASyncWindow::processCallableQueue()
|
|
{
|
|
if (!m_taskQueue.empty()) {
|
|
auto c = m_taskQueue.pop();
|
|
c();
|
|
if (!m_taskQueue.empty()) {
|
|
QTimer::singleShot(0, this, SLOT(processCallableQueue()));
|
|
}
|
|
}
|
|
}
|