qthread

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

Changing GUI directly from Qthread PyQt 5

[亡魂溺海] 提交于 2020-01-01 19:08:00
问题 Hi i have send to my Thread worker link to GUI and update GUI info directly from QThread. Like here: class Worker(QThread): def __init__(self, ui): QThread.__init__(self) self.running = False self.ui = ui def run(self): self.running = True while self.running: info = self.check_info() rows = len(info) self.ui.tableWidget.setRowCount(rows) self.ui.tableWidget.setColumnCount(6) ... In main QMainWindow i just add def __init__(self, parent=None): ....... self.myworker = Worker(self.ui) ..... Is

QThread is creating a memory leak

拥有回忆 提交于 2019-12-31 07:36:07
问题 After much testing and changes to my QT application, Visual Leak Detector identified the source of a pesky leak (8 bytes). VLD reported the QT application is clean except for a QThread* pointer. A bit of implementation background: the application is modelled as a hybrid of solution by Jeffrey Holmes, Bulk download of web pages using Qt. Thanks to Jeffrey for the earlier solution! Questions: Why is QThread* not destroying itself when the worker thread completed its work? How can I force the

GUI become unresponsive while looping

有些话、适合烂在心里 提交于 2019-12-31 04:44:20
问题 After i click the button, the form become unresponsive until the parsing function finish its work. I'd like to move searchAll function to thread. I did read several answers to similar questions, but i didn't understand how. class MyForm(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.buttonOK.clicked.connect(self.searchAll) self.show() def searchAll(self): sID = self.ui.txtSellerID.text() sUrl = "https://removed.com/" + sID + "/p/?section=2

Python access widgets of parent class in Qthread

独自空忆成欢 提交于 2019-12-31 04:38:11
问题 I want to access the parent class widgets in the QThread class This line gives hangs GUI "Example().setWindowTitle("Window")" How can I do that? class Example(QWidget): def __init__(self): super().__init__() self.myclass2 = myclass2() self.myclass2.start() self.initUI() def initUI(self): self.setGeometry(300, 300, 300, 220) self.setWindowTitle('Icon') self.setWindowIcon(QIcon('web.png')) self.show() class myclass2(QThread): def __init__(self, parent=None): super(myclass2, self).__init__

pyqtSignals not emitted in QThread worker

只愿长相守 提交于 2019-12-31 04:13:08
问题 I have an implementation of a BackgroundTask object that looks like the following: class BackgroundTask(QObject): ''' A utility class that makes running long-running tasks in a separate thread easier :type task: callable :param task: The task to run :param args: positional arguments to pass to task :param kawrgs: keyword arguments to pass to task .. warning :: There is one **MAJOR** restriction in task: It **cannot** interact with any Qt GUI objects. doing so will cause the GUI to crash. This

How Start a Qthread from qml?

浪子不回头ぞ 提交于 2019-12-31 02:56:31
问题 I need to Start immediately and stop then a QThread extended class from Qml File. Is there any solution for that? here is my class : class SerialManager : public QThread { Q_OBJECT public: CircularList<unsigned char> buffer_[2]; signals: void dataReady(short *value,int len,unsigned short sample); protected: void run(); }; 回答1: if you have SerialManager like this: class SerialManager : public QThread { Q_OBJECT public: CircularList<unsigned char> buffer_[2]; signals: void dataReady(short

Can two threads read from the same QList at the same time?

帅比萌擦擦* 提交于 2019-12-30 10:26:09
问题 Pretty new to threading and I have this QList that the threads share between them. They all have their own space that they can work on, and the GUI (the model/view) access this list constantly. I then get this crash which points to QDataList.size(). The debugging doesn't really help me since I never come across this issue if I step through the code and when I'm trying to what qList that's crashing, there's no info available. So, my question is: Is it possible to get the Qlists size and read

How to implement a QThread that runs forever{} with a QWaitCondition but still needs to catch another Slot while doing that

微笑、不失礼 提交于 2019-12-30 08:36:14
问题 I implemented a class that can write data to a serial port via a QQueue and read from it by a slot. I use QAsyncSerial for this which in turn uses boost::asio with a callback. The class is moved to a thread and its start() method is executed when the QThread emits "started()" The problem is that I dequeue the QQueue in the start()-method using forever {} and a QWaitCondition. While this is running (which obviously runs forever) the slot connected to the dataReceived signal of QAsyncSerial can

Sharing data across Qt threads

筅森魡賤 提交于 2019-12-30 07:09:07
问题 I'm new to Qt so please excuse the simplicity of the question but I'm a bit confused on the Qt threading. Let's say I have 3 threads: the main default GUI thread, and 2 threads of my own creation (called WorkerThread). Each of my WorkerThreads inherits from QThread and are permanent threads that every so often wake up and send data out a socket and post status on a GUI element. How is the best way to 1) allow the GUI thread to set data in the WorkerThread object that the WorkerThread thread