我試圖從PyQt中的非主線程發送信號,但我不知道什麼是做錯了!當我執行程序失敗,出現此錯誤:QObject :: connect:無法排隊'QTextCursor'類型的參數
QObject::connect: Cannot queue arguments of type 'QTextCursor'
(Make sure 'QTextCursor' is registered using qRegisterMetaType().)
這裏是我的代碼:
class Sender(QtCore.QThread):
def __init__(self,q):
super(Sender,self).__init__()
self.q=q
def run(self):
while True:
pass
try: line = q.get_nowait()
# or q.get(timeout=.1)
except Empty:
pass
else:
self.emit(QtCore.SIGNAL('tri()'))
class Workspace(QMainWindow, Ui_MainWindow):
""" This class is for managing the whole GUI `Workspace'.
Currently a Workspace is similar to a MainWindow
"""
def __init__(self):
try:
from Queue import Queue, Empty
except ImportError:
while True:
#from queue import Queue, Empty # python 3.x
print "error"
ON_POSIX = 'posix' in sys.builtin_module_names
def enqueue_output(out, queue):
for line in iter(out.readline, b''):
queue.put(line)
out.close()
p= Popen(["java -Xmx256m -jar bin/HelloWorld.jar"],cwd=r'/home/karen/sphinx4-1.0beta5-src/sphinx4-1.0beta5/',stdout=PIPE, shell=True, bufsize= 4024)
q = Queue()
t = threading.Thread(target=enqueue_output, args=(p.stdout, q))
t.daemon = True # thread dies with the program
t.start()
self.sender= Sender(q)
self.connect(self.sender, QtCore.SIGNAL('tri()'), self.__action_About)
self.sender.start()
我覺得我送參數給線程的方式是錯誤的... 我需要知道如何將參數發送到線程,在我的情況下,我需要發送q
到工作線程。
可能重複[如何參數發送到的QThread(http://stackoverflow.com/questions/13675140/how-to-send-parameters-to- a-qthread) – ekhumoro
你已經提出過這個問題,而且你還沒有提供任何實際使用QTextCursor的代碼。 –
提問者很可能實際上並未直接使用QTextCursor,而是使用不是GUI線程的線程的GUI代碼。試圖這樣做似乎導致這種由Qt內部代碼引起的錯誤,例如,爲QTextEdit.append()。請參閱:http://stackoverflow.com/questions/2104779/qobject-qplaintextedit-multithreading-issues – svk