【发布时间】:2017-07-19 00:37:58
【问题描述】:
我正在尝试将一个类中的字符串发送到另一个类中的 qtextbrowser,我的 gui 是在 pyqt 中构建的,而我在 python 2.7 中编写的代码。
这是我的测试代码:
class print_text():
def __init__(self):
text1 = "Acesta este un text de proba"
self.classMyWindow = MyWindow()
self.classMyWindow.statusText_updater("Merge ok ")
class systemValues(QThread):
def __init__(self):
QThread.__init__(self)
def __del__(self):
self.wait()
def cpuRunValue(self):
text1 = "Acesta este un text de proba"
self.classMyWindow = MyWindow()
self.classMyWindow.statusText_updater("Merge ok ")
def run(self):
self.cpuRunValue()
class MyWindow(QtGui.QMainWindow):
def __init__(self):
#QtGui.QDialog.__init__(self)
super(MyWindow, self).__init__()
file_path = os.path.abspath("im-manager.ui")
uic.loadUi(file_path, self)
self.myThread = systemValues()
self.myThread.start()
def statusText_updater(self,text):
time_print = time.strftime("%d/%m/%Y-%H:%M:%S")
read1 = self.status.toPlainText()
self.status.setText(text+" >>> "+time_print+" \n"+ read1+" ")
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = MyWindow()
window.show()
# app.exec_()
sys.exit(app.exec_())
我收到此错误:
QPixmap: It is not safe to use pixmaps outside the GUI thread
从另一个类读取字符串或将字符串发送到 qtextbrowser 的正确方法是什么?
我需要这个,因为我的应用需要在不同的线程上读取一些 cpu 和 ram 值,以防止我的应用冻结并在工作完成时显示一条短信。
【问题讨论】:
-
你在哪里定义了 statusText_updater?
-
对不起,我的错误。忘记了这个定义。我更新了代码@eyllanesc
-
MyWindow 是 QMainWindow 还是 QDialog?,您使用的 im-manager.ui 模板是什么?
-
QMainWindow,可以看这里
class MyWindow(QtGui.QMainWindow) -
QtGui.QDialog.__init__(self) super(MyWindow, self).__init__()?
标签: python python-2.7 pyqt pyqt4