qtimer

How to get Duration of audio and video files in Qt without using QMediaPlayer

别等时光非礼了梦想. 提交于 2019-12-23 19:23:17
问题 I have been working on an application where I can traverse the system drives using QDirIterator and look for audio/video files, grab the details using QStandardItemModel and display it on QTreeview. I have been successful in displaying file name, type, size, date-modified but DURATION is something which I am not able to do. Here is the code: // Displays Files in Detail View on Clicking Drive void DetailView::on_DriveView_clicked(const QModelIndex &index) { int m_count_row = 0;

Advice on GUI timer to display background thread's elapsed time?

拟墨画扇 提交于 2019-12-23 19:15:06
问题 Issue I have a PyQt GUI where the user presses a button to start a background thread ( workerThread , which is subclassed from QThread ). I would like to have a timer display (in the form of a QLabel ) to show how much time has elapsed since workerThread started, and I would like this timer to stop as soon as the workerThread exits. Possible solution I've thought about creating another independent thread ( timerThread ) that uses a QTimer to send a signal to a slot to update the QLabel in the

The most accurate timer qt C++

有些话、适合烂在心里 提交于 2019-12-20 08:07:16
问题 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:

How to use a QTimer in a separate QThread

…衆ロ難τιáo~ 提交于 2019-12-20 05:21:52
问题 I have some computationally heavy task that I want to run in a loop after every 5 seconds without blocking the main event-loop. For this, I intend to use a QTimer and a separate thread to run it. I have tried the following code but it has not worked so far: @pyqtSlot() def heavy_task_function(): # Sleep for 10 seconds to simulate heavy computation time.sleep(10) print "First Timer Fired" if __name__ == "__main__": app = QCoreApplication.instance() if app is None: app = QApplication(sys.argv)

How to use a QTimer in a separate QThread

天涯浪子 提交于 2019-12-20 05:21:21
问题 I have some computationally heavy task that I want to run in a loop after every 5 seconds without blocking the main event-loop. For this, I intend to use a QTimer and a separate thread to run it. I have tried the following code but it has not worked so far: @pyqtSlot() def heavy_task_function(): # Sleep for 10 seconds to simulate heavy computation time.sleep(10) print "First Timer Fired" if __name__ == "__main__": app = QCoreApplication.instance() if app is None: app = QApplication(sys.argv)

How to run a timer inside a QThread?

六眼飞鱼酱① 提交于 2019-12-18 12:38:47
问题 I would like to run a timer inside a QThread. I have written some code in which i am getting some error during the run time. Please guide me into the right direction. What am I doing wrong? (Parent is QThread(0x1498d10), parent's thread is QThread(0x11272b0), current thread is QThread(0x1498d10) mainwindow.h //main .h file #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "mythread.h" namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT

Exit QThread when GUI Application exits

房东的猫 提交于 2019-12-12 01:23:02
问题 I have the following worker class: class MediaWorker : public QObject { Q_OBJECT public: explicit MediaWorker(QObject *parent = 0); ~MediaWorker(); void Exit(); signals: void Finished(); public slots: void OnExecuteProcess(); }; In MediaWorker.cpp void MediaWorker::Exit() { emit Finished(); } void MediaWorker::OnExecuteProcess() { qDebug() << "Worker Thread: " << QThread::currentThreadId(); } In my MainWindow I do the following: this->threadMediaWorker = new QThread(); this->mediaWorker = new

Is QTimer smart enough to resynchronize itself

喜你入骨 提交于 2019-12-11 12:35:24
问题 Let's say we start a QTimer with a 100ms interval at t0. Let's say first timeout occurs at t0+100ms. Fine. Let's say that, due to huge CPU load and/or lots of events having to be handled by the event loop, second timeout occurs at t0+230ms. Let's say CPU is back to normal load. Is their any chance that third timeout could occur at t0+300ms ( QTimer object realising it was late and trying to correct that by resynchronizing itself), or will it most likely timeout at t0+330ms? 回答1: Per QTimer

QT: How to loop a method every second? C++

拥有回忆 提交于 2019-12-11 03:38:51
问题 I've created a Qt project which displays a circle on a widget. Then I have a method which redraws the circle at different positions every time I call the method. What I want is to run that method in a for loop, say ten times, and be shown each of the 10 positions that the circle is redrawn in every one second. Something along the lines of: void method::paintEvent(QPaintEvent * p) { //code for(int i=0; i<10;i++)//do this every second { method(circle[i]); //co-ordinates change circle[i].pain( &

Can I use QTimer to implement a multthreaded algorithm?

风格不统一 提交于 2019-12-11 02:28:42
问题 currently I need to implement a multi-threaded algorithm based on Qt. Maybe I should try to extend QThread . But before that, I'd like to ask, if I can just use two QTimer s timer1 , timer2 , and connect their timeout signal to the threads respectively, to implement a "fake" multi-threaded program? 回答1: You can connect the timeout() signal of QTimer to the appropriate slots, and call start() . From then on, the timers will emit the timeout() signals at constant intervals. But the two timers