qtimer

Using QT, how to call function once after a certain interval, even if more calls may occur?

与世无争的帅哥 提交于 2019-12-07 02:57:49
问题 I am having a hard time wording this question even though I don't think its that complicated. I want to do something simalar to QTimer::singleshot() but I want it to still only call the SLOT once even if QTimer::singleshot() is called multiple times before it fires. 回答1: This should work. class MyObject { // ... QTimer* mTimer; } MyObject::MyObject() { mTimer = new QTimer(this); mTimer->setSingleShot(true); connect(mTimer, SIGNAL(timeout()), SLOT(doStuff())); } MyObject::startOrResetTimer() {

Using QT, how to call function once after a certain interval, even if more calls may occur?

时光毁灭记忆、已成空白 提交于 2019-12-05 06:46:01
I am having a hard time wording this question even though I don't think its that complicated. I want to do something simalar to QTimer::singleshot() but I want it to still only call the SLOT once even if QTimer::singleshot() is called multiple times before it fires. Timmmm This should work. class MyObject { // ... QTimer* mTimer; } MyObject::MyObject() { mTimer = new QTimer(this); mTimer->setSingleShot(true); connect(mTimer, SIGNAL(timeout()), SLOT(doStuff())); } MyObject::startOrResetTimer() { mTimer->start(1000); } If you only want to call a slot once off a timer you could look at something

how to add a 1 second delay using Qtimer

筅森魡賤 提交于 2019-12-04 16:27:56
问题 I currently have a method which is as follows void SomeMethod(int a) { //Delay for one sec. timer->start(1000); //After one sec SomeOtherFunction(a); } This method is actually a slot that is attached to a signal. I would like to add a delay of one sec using Qtimer.However I am not sure on how to accomplish this. Since the timer triggers a signal when its finished and the signal would need to be attached to another method that does not take in any parameters. Any suggestion on how I could

How to use QTimer inside QThread which uses QWaitCondition? (pyside)

和自甴很熟 提交于 2019-12-04 15:11:21
I'm using pyside but (I think) is a generic Qt question. I know that QThread implementation calls ._exec() method so we should have an event loop on a started QThread. This way we can use QTimer on that thread (I've done this and it works perfectly). My problem is when QWaitCondition is also used, I'd like to have a "consumer" thread with a infinite loop waiting to be notify (from producers) on the QWaitCondition. The problem I have is that with this design I cannot use QTimer inside the consumer Thread. This is a snippet of the scenario I'm trying to explain: from PySide import QtGui from

Why I get “QTimer can only be used with threads started with QThread” messages if I have no QTimer in my code?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 03:07:33
When (and only when) I quit my application, these (and only these) repeated message appear on the command prompt: QObject::startTimer: QTimer can only be used with threads started with QThread QObject::startTimer: QTimer can only be used with threads started with QThread QObject::startTimer: QTimer can only be used with threads started with QThread This is quite strange for me, because I never use QTimer in my code (or QThread). In fact, no errors or crashes happen using the application, so this is not a real problem, actually. This happen in both Windows and Linux OSs. All my imports: from _

Does a QTimer object run in a separate thread? What is its mechanism?

与世无争的帅哥 提交于 2019-12-03 05:40:57
问题 When I create a QTimer object in Qt 5, and start it using the start() member function, is a separate thread created that keeps track of the time and calls the timeout() function at regular intervals? For example, QTimer *timer = new QTimer; timer->start(10); connect(timer,SIGNAL(timeout()),someObject,SLOT(someFunction())); Here, how does the program know when timeout() occurs? I think it would have to run in a separate thread, as I don't see how a sequential program could keep track of the

Does a QTimer object run in a separate thread? What is its mechanism?

强颜欢笑 提交于 2019-12-02 18:07:16
When I create a QTimer object in Qt 5, and start it using the start() member function, is a separate thread created that keeps track of the time and calls the timeout() function at regular intervals? For example, QTimer *timer = new QTimer; timer->start(10); connect(timer,SIGNAL(timeout()),someObject,SLOT(someFunction())); Here, how does the program know when timeout() occurs? I think it would have to run in a separate thread, as I don't see how a sequential program could keep track of the time and continue its execution simultaneously. However, I have been unable to find any information

Substitute for sleep function in Qt/C++

廉价感情. 提交于 2019-12-02 15:39:35
问题 So I am writing a program that displays each letter of a word for 1 second with a 1 second interval between the letters. (It's for a spelling exercise for grade 1). I am currently using the sleep function to "pause" the program for 1 second before it "updates" again. After that it displays the word for a second and then removes it. I repaint before the sleep function, else it does not seem to update in time. Here is the basic function: QString word = "apple"; QThread thread; for(int i = 0; i

The most accurate timer qt C++

故事扮演 提交于 2019-12-02 13:38:04
I use QTimer to send periodically 'Ping' packet to the server (MQTT client). But it timer is not absolutely accurate. After some time of working it has some delay and server broken connection. I try to use different Qt::TimerType, but it does not help. I need the most accurate timer. Do you have any ideas? Thank you! EDIT (Frederik solution) I have done something this: tthread.h class TThread : public QThread { Q_OBJECT void run(); public: explicit TThread(QObject *parent = 0); signals: private slots: void timerOut(); }; tthread.cpp TThread::TThread(QObject *parent) : QThread(parent) { } void

QObject::startTimer: Timers can only be used with threads started with QThread

末鹿安然 提交于 2019-12-01 06:56:10
问题 I am trying to start a Timer in a worker thread's event loop, but I get this error: QObject::startTimer: Timers can only be used with threads started with QThread Whats wrong with this? #include <QObject> #include <QThread> #include <QTimer> class A : public QObject { Q_OBJECT public: A(); private: QThread m_workerThread; QTimer m_myTimer; }; A::A() { this->moveToThread(&m_workerThread); m_myTimer.moveToThread(&m_workerThread); m_workerThread.start(); m_myTimer.start(1000); } 回答1: I Think i