0
長話短說,再次。我正在編寫非常簡單的文本輸出到Qt的QTextBrowser窗口(存儲在window.ui中)的Python庫。據我以前發現,Qt對象不應該直接訪問。那麼,什麼是擺脫的正確方法:PyQT無法排隊QTextCursor - 如何正確更改窗口內容
QObject::connect: Cannot queue arguments of type 'QTextCursor'
(Make sure 'QTextCursor' is registered using qRegisterMetaType().)
從其他線程「打印」時出現錯誤?
# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore, uic
import sys
import time
def async(func):
from threading import Thread
from functools import wraps
@wraps(func)
def async_func(*args, **kwargs):
func_hl = Thread(target=func, args=args, kwargs=kwargs)
func_hl.start()
return func_hl
return async_func
class GuiFile(QObject): # add also GUI_FORM
def __init__(self, filename):
QObject.__init__(self, None)
self.filename = filename
self.myapp = sys.argv
self.app = QtGui.QApplication(self.myapp)
def show(self):
self.window = uic.loadUi(self.filename)
self.window.show()
def pprint(self, text):
gui_object = self.window.outbox
gui_object.insertHtml(text + '<br>')
gui_object.moveCursor(QtGui.QTextCursor.End)
if __name__ == '__main__':
@async
def other_thead():
time.sleep(1)
for x in xrange(3):
print x
gui.pprint(u'Hello %s' % x)
gui = GuiFile('window.ui')
gui.show()
other_thead()
sys.exit(gui.app.exec_())
請明確告訴我,'cus我完全被卡住了,並且困惑地讀到了關於這些插槽和Qt的問題。
window.ui鏈接是在這裏:https://yadi.sk/d/U3esbMcIkvbFc
upd1:
也是我試圖發出信號,這樣的:
self.connect(self.window.outbox, SIGNAL("print"), self.real_print)
def real_print(self, text, **kwargs):
print 'RP'
gui_object = self.window.outbox
""" What if we print to other field? """
if kwargs.get('field'):
field = kwargs['field']
for elem in dir(self.window):
if str(elem) == field:
gui_object = getattr(self.window, elem)
gui_object.insertHtml(text + '<br>')
gui_object.moveCursor(QTextCursor.End)
def pprint(self, text, **kwargs):
self.emit(SIGNAL("print"), text)
,但它仍然沒有工作。