I need a way to run an update function of my own in the main thread. I couldn\'t find a signal that would tick me every time the main loop runs.
Am I doing this wr
Alternatively, if you want to execute your code every time the event loop runs you can use the slot method invocation via the queued connection:
class EvtLoopTicker : public QObject
{
Q_OBJECT
public:
EvtLoopTicker(QObject *pParent = nullptr)
: QObject(pParent)
{}
public slots:
void launch()
{
tickNext();
}
private slots:
void tick()
{
qDebug() << "tick";
// Continue ticking
tickNext();
}
private:
void tickNext()
{
// Trigger the tick() invokation when the event loop runs next time
QMetaObject::invokeMethod(this, "tick", Qt::QueuedConnection);
}
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
EvtLoopTicker ticker;
ticker.launch();
return a.exec();
}