Pyside2信号插槽2d阵列签名定义,等效于列表列表

时间:2018-10-03 19:06:42

标签: python pyside pyside2

我试图将发出2D数组的signal连接到处理列表列表的slot

我在@Slot(list)定义和slot中使用SIGNAL("slot_method(QList<QList<QString>>)"),但这似乎不起作用。

我想知道用Qt来正确转换列表列表是什么。

1 个答案:

答案 0 :(得分:1)

在Python中没有2D列表,只有列表,因此您必须使用签名list

示例:

from PySide2 import QtCore


class Sender(QtCore.QObject):
    signal = QtCore.Signal(list)

    def on_test(self):
        l = [["a", "b", "c", "d"], ["A", "B", "C", "D"]]
        self.signal.emit(l)


class Receiver(QtCore.QObject):
    @QtCore.Slot(list)
    def on_receiver(self, l):
        print(l)
        QtCore.QCoreApplication.quit()


if __name__ == '__main__':
    import sys
    app = QtCore.QCoreApplication(sys.argv)

    sender = Sender()
    receiver = Receiver()
    sender.signal.connect(receiver.on_receiver)
    QtCore.QTimer.singleShot(1000, sender.on_test)

    sys.exit(app.exec_())