qtimer

What is the alternative to QTimer?

巧了我就是萌 提交于 2021-02-10 15:06:03
问题 The slot function QTimer::start have a interval of millisecond: Starts or restarts the timer with a timeout interval of msec milliseconds. But msec is a int type and couldn't take a long interval. What is a alternative to QTimer which could take a long interval ? 回答1: In this case you can use something like an hourly timer connected to a function or lambda that checks the current timepoint against a target... /* * We want to trigger some event one year from now. */ auto endpoint = QDateTime:

How to set PyQt5 Qtimer to update in specified interval?

a 夏天 提交于 2021-02-10 14:18:19
问题 I would like to update the Qtimer according to a framerate of 15 FPS - so my def update(): recieves a signal every 0,06 s. Can you help me? I have attached a code example below where my setInterval input is 1/15, but I dont know if that is the way to go. Thanks. from PyQt5 import QtCore def update(): print('hey') fps = 15 timer = QtCore.QTimer() timer.timeout.connect(update) timer.setInterval(1/fps) timer.start() 回答1: You have the following errors: setInterval() receives the time in

How can I change the interval of a Qtimer inside of a Qthread?

杀马特。学长 韩版系。学妹 提交于 2020-06-28 03:58:11
问题 I want to be able to change the interval time of a QTimer inside of a QThread. This is my code. import sys from PyQt5 import QtWidgets from PyQt5.QtWidgets import QApplication, QMainWindow from PyQt5.QtCore import QObject, QTimer, QThread class Worker(QObject): def __init__(self): QObject.__init__(self) self.timer = QTimer(self) self.timer.timeout.connect(self.work) def start(self): self.timer.start(1000) def work(self): print("Hello World...") def set_interval(self, interval): self.timer

PyQt5 QTimer count until specific seconds

南笙酒味 提交于 2020-03-03 05:19:03
问题 I am creating a program in python and i am using pyqt. I am currently working with the QTimer and i want to print "timer works" every seconds and stop printing after 5 seconds. Here is my code: timers = [] def thread_func(): print("Thread works") timer = QtCore.QTimer() timer.timeout.connect(timer_func) timer.start(1000) print(timer.remainingTime()) print(timer.isActive()) timers.append(timer) def timer_func(): print("Timer works") 回答1: Below is a simple demo showing how to create a timer

QThread and QTimer

跟風遠走 提交于 2020-01-20 06:51:05
问题 I'm working on an application developed with Qt 4.6. I want to create a custom timer that counts in a separate thread. However, I want this timer to be able to send signals to the main thread. I subclassed QThread but it doesn't seem to work. Here is Timer.h: #ifndef TIMER_H #define TIMER_H #include <QtCore/QObject> #include <QtCore/QThread> #include <QtCore/QTimer> class Timer : public QThread { Q_OBJECT public: explicit Timer(QObject *parent = 0); ~Timer(); // true if the timer is active

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

好久不见. 提交于 2020-01-01 19:27:13
问题 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

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

好久不见. 提交于 2020-01-01 08:43:13
问题 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

Insert text in while(1) loop to texteditor in QT

爷,独闯天下 提交于 2019-12-25 07:49:12
问题 Am trying to print "Some text" to QTextBrowser, continuously for "n" time. Where "n" is integer. For this I have used QTimer::SingleShot for timing. Once the timeout is triggered a FLAG is set to false and this "FLAG" is monitored in while loop to break when FLAG is false and it shall insert the text till FLAG is set to FALSE. Initial value for FLAG is true. #include "mainwindow.h" #include "ui_mainwindow.h" #include <QThread> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui

QTimer becomes faster with each start/stop

被刻印的时光 ゝ 提交于 2019-12-24 02:55:17
问题 I'm using a QTimer to smoothly change the size of a label: it should slowly grow when I hover the mouse over a button, and slowly collapse (decrease it's size until it dissapears) when the mouse leaves the button. I have two timers in my form's class: QTimer oTimer, cTimer;//oTimer for expanding, cTimer for collapsing In my form's constructor, I'm setting the timer's values and connecting the button's mouseOver and mouseOut signals to my form's slots: oTimer.setInterval( 25 ); cTimer