blob: e92af6f2adc540884f7f09361e680a2394eeffe3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#ifndef THREAD_H
#define THREAD_H
#include <contextproperty.h>
#include <QThread>
#include <QDebug>
class Listener : public QObject
{
Q_OBJECT
public:
Listener()
{
cp = new ContextProperty("test.int");
connect(cp, SIGNAL(valueChanged()), this, SLOT(onValueChanged()));
qDebug() << "**** Starting to wait";
cp->waitForSubscription();
qDebug() << "**** Waiting is done";
qDebug() << "After waiting, the value is" << cp->value();
sleep(1);
qDebug() << "After waiting 1 s more, the value is" << cp->value();
}
ContextProperty* cp;
public slots:
void onValueChanged()
{
qDebug() << "Listener::valueChanged(), and current thread is" << QThread::currentThread();
qDebug() << "The value is:" << cp->value();
// exit(1);
}
};
class Thread : public QThread
{
Q_OBJECT
protected:
void run()
{
qDebug() << "SUB THREAD:" << QThread::currentThread();
Listener listener;
exec();
}
};
#endif
|