qthread

Controlling a QThread in pyqt5?

非 Y 不嫁゛ 提交于 2019-12-20 05:30:09
问题 I wrote a webcam app with pyqt5 and opencv, which saves live videos. screenshot : https://i.hizliresim.com/kM8GOD.png I used a QThread for streaming without blocking main app. But the problem is, I can't control streaming&saving videos with my buttons. It start recording when I run main program but I want to make it with RUN button and save with STOP button. I tried do it with recording parameter but it's weird a bit. Program starts recording initially and first time I pressed stop it saves

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 generate an exception in a different thread

偶尔善良 提交于 2019-12-20 04:25:27
问题 good night I am trying to generate an exception in this example code, the exception of generates if at the time of changing the text in the QLineEdit the text could not be converted into a number. However, when I'm running, I get an error and the program stops error: QObject::setParent: Cannot set parent, new parent is in a different thread this is the code: from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox from PyQt5 import QtCore from PyQt5 import uic import threading class

In which thread is a slot executed, and can I redirect it to another thread?

故事扮演 提交于 2019-12-20 04:20:00
问题 While learning more about the Signal/Slot mechanic in Qt, I was confused in which context a slot is executed, so I wrote the following example to test it: from PyQt5.Qt import * # I know this is bad, but I want a small example import threading def slot_to_output_something ( something ): print( 'slot called by', threading.get_ident(), 'with', something ) class Object_With_A_Signal( QObject ): sig = pyqtSignal( str ) class LoopThread( QThread ): def __init__ ( self, object_with_a_signal ): self

Implementation of Inter Thread Communication in Qt

[亡魂溺海] 提交于 2019-12-20 03:25:07
问题 I am having problem to implement the following scenario. My problem statement goes like this: I have 3 threads. ThreadCamera for grabbing frames from a camera. ThreadProcess for processing (doing some image processing with OpenCV on the image/frame grabbed) the frame and main GUI Thread for displaying the image. I don't know how much time ThreadProcess will take to process an image. So I want to pass the image from ThreadCamera to ThreadProcess , do some image processing on the image and pass

How to implement frequent start/stop of a thread (QThread)

流过昼夜 提交于 2019-12-19 03:36:11
问题 I need to start and stop a thread very frequently using push button..I am using Qt. Recently I learned to create a QObject of the worker and move it to the object of the QThread as the correct way of implementing threads in Qt. Following is my implementation... Worker.h class worker : public QObject { Q_OBJECT public: explicit worker(QObject *parent = 0); void StopWork(); void StartWork(); bool IsWorkRunning(); signal: void SignalToObj_mainThreadGUI(); public slots: void do_Work(); private:

How to setup QSerialPort on a separate thread?

我们两清 提交于 2019-12-18 13:34:18
问题 Following the official documentation I'm trying to do this: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QThread *thread = new QThread; Worker *worker= new Worker(); worker->moveToThread(thread); //init connections thread->start(); } Worker constructor: Worker::Worker(QObject *parent) : QObject(parent) { serial = new QSerialPort(this); //passing the parent, which should be the current thread } No compiling errors but when I execute it throws me this: QObject: Cannot create

How to signal from a running QThread back to the PyQt Gui that started it?

≡放荡痞女 提交于 2019-12-18 13:24:50
问题 I am trying to understand how to use signaling from a Qthread back to the Gui interface that started. Setup: I have a process (a simulation) that needs to run almost indefinitely (or at least for very long stretches of time)., While it runs, it carries out various computations, amd some of the results must be sent back to the GUI, which will display them appropriately in real time. I am using PyQt for the GUI. I originally tried using python's threading module, then switched to QThreads after

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