
Originally Posted by
T_h_e_o
Suppose thread a is running and object A emits signal sig1 twice before thread c runs. After that, thread c runs. Will the slot of object C be called once or twice?
Twice.
Similarly to the situation above, add a thread b with object B which has a signal sig2 that is connected to the same slot of object C. Situation: thread a runs, object A emits signal sig1. Then thread b runs, object B emits signal sig2. Then thread c runs. Will the slot of object C be called once or twice?
Twice.
I know I posted a reply to your thread pretty quickly, but wouldn't it give you more satisfaction to just write an example program and test it yourself?
#include <QCoreApplication>
#include <QThread>
#include <QtDebug>
Q_OBJECT
public:
A(){}
public slots:
void emitSignal() { emit sig1(); }
signals:
void sig1();
};
Q_OBJECT
public:
C(){}
public slots:
void someSlot() { qDebug() << Q_FUNC_INFO; }
};
#include "main.moc"
int main(int argc, char **argv) {
A *a = new A;
C *c = new C;
QObject::connect(a,
SIGNAL(sig1
()), c,
SLOT(someSlot
()));
c->moveToThread(&t);
a->emitSignal();
a->emitSignal();
t.start();
return app.exec();
}
#include <QCoreApplication>
#include <QThread>
#include <QtDebug>
class A : public QObject {
Q_OBJECT
public:
A(){}
public slots:
void emitSignal() { emit sig1(); }
signals:
void sig1();
};
class C : public QObject {
Q_OBJECT
public:
C(){}
public slots:
void someSlot() { qDebug() << Q_FUNC_INFO; }
};
#include "main.moc"
int main(int argc, char **argv) {
QCoreApplication app(argc, argv);
QThread t;
A *a = new A;
C *c = new C;
QObject::connect(a, SIGNAL(sig1()), c, SLOT(someSlot()));
c->moveToThread(&t);
a->emitSignal();
a->emitSignal();
t.start();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks