简体   繁体   中英

How to use QTimer inside QThread?

I have a class, a subclass of QObject. I am creating an instance for that class inside a QThread. I want to use QTimer in my class. But the timer is not starting because the caller thread is a woker thread. How can i achieve the solution?

Well, can you make a slot in some helper object that lives in main thread and is a member of the class and dispatch the timer creation and start to it from your class (and optionally check if the current thread is not the event loop since then it's safe to start the timer there) ? So then when you need to create the timer you would just fire a signal to your helper object in main thread and it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM