class Foo {
private:
public:
void Foo
(QTimer *timer
) : timer
(timer
) { }
void bar () {
this->timer->start();
}
};
...
Foo *foo = new foo(timer);
obj.func(foo);
timer->connect(timer, &QTimer::timeout, [] {
// do something
});
class Foo {
private:
QTimer *timer = nullptr;
public:
void Foo (QTimer *timer) : timer(timer) { }
void bar () {
this->timer->start();
}
};
...
QTimer *timer = new QTimer();
Foo *foo = new foo(timer);
obj.func(foo);
timer->connect(timer, &QTimer::timeout, [] {
// do something
});
To copy to clipboard, switch view to plain text mode
The program runs in the following order:
1. a third party library creates a new thread.
2. foo object is registered in the library through its obj::func() method.
3. the library calls foo::bar() method.
But after that, the program doesn't work with error message
QObject::startTimer: Timers cannot be started from another thread.
Could you give me some advice if you have a good idea? Thanks.
Bookmarks