QObject :: connect:不能在PySide中排队类型为“object”的参数 [英] QObject::connect: Cannot queue arguments of type 'object' in PySide

查看:665
本文介绍了QObject :: connect:不能在PySide中排队类型为“object”的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PySide(Python Qt绑定)。



我有一个类QThread的工作线程,它更新主要的GUI线程(更新QTableWidget)通过信号/插槽机制。



在我的工作线程中,我有以下内容:

  self.emit(SIGNAL(alterTable(object),params)

在我的GUI线程我有这个:

  self.connect(self.worker,SIGNAL(alterTable(object)),self.updateMainTable, Qt.AutoConnection)

由于有几个类似的工作线程运行所有连接到同一个插槽( self.updateMainTable ),我应该使用AutoConnection(并因此使用QueuedConnection)。使用 Qt.DirectConnection 但是当我尝试使用AutoConnection时,我收到以下错误:

$ b $($)

b

  QObject :: connect:无法排队参数o f键入'object'
(确保使用qRegisterMetaType()注册object)

我已经有Google Googled试图找出一种如何使用PySide中的 qRegisterMetaType()的方式,无济于事。我在网上找到的所有资源都指向一个C ++语法/文档。



如果有任何区别,所讨论的对象是一个 dict 大部分时间。

解决方案

我想我已经找到了一个答案,但是一个可行的解决方案。



我将所有的信号切换到新式语法。如果有人想知道,我通过在我的工人类中定义一个自定义信号来做到这一点。所以我的代码看起来像这样

  class Worker(QThread):

alterTable = Signal )

def __init __(self,parent = None):
....
self.alterTable.emit(parameters)


class GUI(QMainWindow):

def __init __(self,parent = None):
WorkerModule.Worker()。alterTable.connect(self.myMethod)

由于某种原因,Signal必须在QThread类中;否则,Qt抱怨信号没有属性连接错误,这是非常奇怪的。


I am using PySide (Python Qt binding).

I have a worker thread of class QThread that updates the main GUI thread (updates the QTableWidget) through signal/slot mechanism.

In my worker thread, I have the following:

self.emit(SIGNAL("alterTable(object"), params)

In my GUI thread I have this:

self.connect(self.worker, SIGNAL("alterTable(object)"), self.updateMainTable, Qt.AutoConnection)

Since there are several similar worker threads running all connecting to the same slot (the self.updateMainTable), I should use the AutoConnection (and consequently the QueuedConnection). Using the Qt.DirectConnection works, but it is not safe (or so I have been told).

But when I try to use the AutoConnection, I get the following error:

QObject::connect: Cannot queue arguments of type 'object'
(Make sure 'object' is registered using qRegisterMetaType().)

I have Googled for eons trying to figure out a way how to use the qRegisterMetaType() in PySide, to no avail. All the resources I found online point to a C++ syntax/documentation.

If it makes any difference, the object in question is a dict most of the time.

解决方案

I guess I have found an answer myself, well not exactly an answer, but a workable solution.

I switched all the Signals to the new-style syntax. In case anyone is wondering, I did that by defining a custom signal in my worker class. So my code looks something like this

class Worker(QThread):

    alterTable = Signal(dict)

    def __init__(self, parent=None):
        ....
        self.alterTable.emit(parameters)


class GUI(QMainWindow):

    def __init__(self, parent=None):
        WorkerModule.Worker().alterTable.connect(self.myMethod)

For some reason the Signal has to be inside the QThread class; otherwise, Qt complains about "Signal has no attribute connect" error, which is very weird.

这篇关于QObject :: connect:不能在PySide中排队类型为“object”的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆