I think you overdid it. The beauty of Qt is that what you are trying to do is very easy.
, , QTimer - , . Qt . Qt , , QObjects. , concurrency - Qt /. , , Qt , - , .
, , , - , timeout().
A QTimer , , , , QObject. QObjects , , QObject::moveToThread(QThread*).
invokeMethod . , , . , . , , a QMetaCallEvent QObject, . , . , , timeout().
, T main() QObject, , - , QtConcurrent. QtConcurrent QObject.
, , :
[] () {
sapp s;
s.f();
QEventLoop l;
l.exec();
}
SSCCE , Qt. QtConcurrent, : qApp->exit() exit() - a.exec() ( ?). wait() , main() - , QThreads, .
exit() , , , - API- C exit()s.
, a QTimer QObject . , , QBasicTimer, , QObject::startTimer(). QObject::timerEvent(). , . , ( ) , QStrings 1000 . . .
: , , - . 100 , . . , #include "filename.moc" filename.cpp. , Java. . , .
#include <QtCore/QTimer>
#include <QtCore/QDebug>
#include <QtCore>
#include <QtCore/QCoreApplication>
class Class : public QObject
{
Q_OBJECT
QTimer timer;
int n;
private slots:
void timeout() {
qDebug() << "hi";
if (! --n) {
QThread::currentThread()->exit();
}
}
public:
Class() : n(5) {
connect(&timer, SIGNAL(timeout()), SLOT(timeout()));
timer.start(500);
}
};
void fun()
{
Class c;
QEventLoop loop;
loop.exec();
qApp->exit();
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QtConcurrent::run(&fun);
return a.exec();
}
#include "main.moc"