qthread

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

How to kill a running thread

可紊 提交于 2020-05-27 19:01:45
问题 I have a dialog that show the progress of a running thread: from PyQt5.QtWidgets import * from PyQt5.uic import loadUi from PyQt5.QtCore import * class LoaderProgress(QDialog): def __init__(self, parent=None): super(LoaderProgress, self).__init__(parent) loadUi("CliReportsUI/loaderprogress.ui", self) self.pbLoader.setValue(0) self.btn_cancel.clicked.connect(self.killthread) def watchthread(self,worker): self.thread = worker(self) self.thread.totsignal.connect(self.pbLoader.setMaximum) self

How to kill a running thread

倾然丶 夕夏残阳落幕 提交于 2020-05-27 19:00:54
问题 I have a dialog that show the progress of a running thread: from PyQt5.QtWidgets import * from PyQt5.uic import loadUi from PyQt5.QtCore import * class LoaderProgress(QDialog): def __init__(self, parent=None): super(LoaderProgress, self).__init__(parent) loadUi("CliReportsUI/loaderprogress.ui", self) self.pbLoader.setValue(0) self.btn_cancel.clicked.connect(self.killthread) def watchthread(self,worker): self.thread = worker(self) self.thread.totsignal.connect(self.pbLoader.setMaximum) self

How to kill a running thread

假如想象 提交于 2020-05-27 19:00:32
问题 I have a dialog that show the progress of a running thread: from PyQt5.QtWidgets import * from PyQt5.uic import loadUi from PyQt5.QtCore import * class LoaderProgress(QDialog): def __init__(self, parent=None): super(LoaderProgress, self).__init__(parent) loadUi("CliReportsUI/loaderprogress.ui", self) self.pbLoader.setValue(0) self.btn_cancel.clicked.connect(self.killthread) def watchthread(self,worker): self.thread = worker(self) self.thread.totsignal.connect(self.pbLoader.setMaximum) self

PyQt: QThreadPool with QRunnables taking time to quit

两盒软妹~` 提交于 2020-05-23 12:58:28
问题 I've a class who create QRunnables and start them in a QThreadPool instance. My threads are working well, but in case user want to quit application, the application takes a long time to stop. Certainly due to the fact that the requests launched take time. Here is a snippet code of how I use QThreadPool, QRunnables: import sys from PyQt5.Qt import QThreadPool, QApplication, QWidget, QVBoxLayout from PyQt5.Qt import QTimer, QObject, QPushButton, QLabel from PyQt5.Qt import QRunnable class

How to create qDebug signal from another thread to the Qt5 GUI thread

北城以北 提交于 2020-05-14 12:15:13
问题 I am trying to display log messages from a work thread in a GUI. I am trying to follow redirect qDebug to QTextEdit It started to work fine, but I am stuck, how to program QObject::connect(otherThread, SIGNAL(debug(QString)), s_textEdit, SLOT(append(QString)), Qt::QueuedConnection); The principle I see, that one signal in the thread shall be connected to a slot in the GUI thread; but how to trigger that signal? Also, I make some logging with QDebug , but also some output to std::cerr . Can I

How to create qDebug signal from another thread to the Qt5 GUI thread

我的未来我决定 提交于 2020-05-14 12:13:30
问题 I am trying to display log messages from a work thread in a GUI. I am trying to follow redirect qDebug to QTextEdit It started to work fine, but I am stuck, how to program QObject::connect(otherThread, SIGNAL(debug(QString)), s_textEdit, SLOT(append(QString)), Qt::QueuedConnection); The principle I see, that one signal in the thread shall be connected to a slot in the GUI thread; but how to trigger that signal? Also, I make some logging with QDebug , but also some output to std::cerr . Can I

How to create qDebug signal from another thread to the Qt5 GUI thread

有些话、适合烂在心里 提交于 2020-05-14 12:13:22
问题 I am trying to display log messages from a work thread in a GUI. I am trying to follow redirect qDebug to QTextEdit It started to work fine, but I am stuck, how to program QObject::connect(otherThread, SIGNAL(debug(QString)), s_textEdit, SLOT(append(QString)), Qt::QueuedConnection); The principle I see, that one signal in the thread shall be connected to a slot in the GUI thread; but how to trigger that signal? Also, I make some logging with QDebug , but also some output to std::cerr . Can I

How to create qDebug signal from another thread to the Qt5 GUI thread

血红的双手。 提交于 2020-05-14 12:13:10
问题 I am trying to display log messages from a work thread in a GUI. I am trying to follow redirect qDebug to QTextEdit It started to work fine, but I am stuck, how to program QObject::connect(otherThread, SIGNAL(debug(QString)), s_textEdit, SLOT(append(QString)), Qt::QueuedConnection); The principle I see, that one signal in the thread shall be connected to a slot in the GUI thread; but how to trigger that signal? Also, I make some logging with QDebug , but also some output to std::cerr . Can I

用事件队列解决QT GUI的操作顺序问题

我怕爱的太早我们不能终老 提交于 2020-03-21 09:28:50
原文: https://www.cnblogs.com/Philip-Tell-Truth/p/6295186.html GUI操作顺序问题引发异常 有时候我们使用写GUI程序的时候会遇到这样的问题:比如在程序中,建立了一个列表的GUI。这个列表是随着时间不断更新的,而且操作也会读取这个列表GUI的内容。 如果这个程序是多线程的程序,而且只是除了GUI的线程不操作,只是其他线程操作这个列表GUI,那么这个问题很简单,只用加互斥锁就可以了。但如果GUI线程自己本身也要操作这个列表,那么这个问题就很麻烦了。 我们可以很容易地想到一种场景,比如GUI线程读了列表的一些表项(比如选定),此时线程中的某个方法keep了这些表项的指针,然而此时很不幸别的线程有一个请求需要删除列表中的一些表项,并且这些表项有一些包含在了我们的选定内容里,我们知道几乎所有的语言操作GUI时都要进入GUI线程里面操作,那么我们刚才选定表项的那个方法会被打断,然后进入删除表项方法,在删除了表项以后再次回到选定表项方法时,我们的选定的表项有一些已经被删除了,此时我们再进行操作很有可能不符合我们的要求。 如果你是用一般是用C#,JAVA这种不用自己管理内存的语言,那还好,只是结果可能不对,但是如果是用C++这种需要我们自己管理内存的来写,很有可能我们会操作一个被释放了内存的对象,然后程序崩掉,这样的情况是我们不想看到的。