0

I'm developing an application with PySide 1.1.2, which is before the new style signals and slots were integrated. I haven't had any issue with most of my custom signals, except those which accept unicode or str types. Those with no parameters, or other types work just fine, but with unicode or str parameters, I get the error: "TypeError: Value types used on meta functions (including signals) need to be registered on meta type: str" on the emit statement.

Example of statements (these are of course in different classes):

self.emit(QtCore.SIGNAL('setCountType(str)'), self.countType)

self.connect(self.parent, QtCore.SIGNAL('setCountType(str)'), self.setCountType)

# part of a class that inherits from QWidget
def setCountType(self, value):
  self.countType = value

The emit statement is the one that throws the error.

4

1 回答 1

1

PySide 1.1.2 支持新样式。就我而言,使用“字符串”的信号完美无缺。如果您需要帮助,请查看:http: //qt-project.org/wiki/Signals_and_Slots_in_PySide

一个例子:

import sys
from PySide.QtGui import *
from PySide.QtCore import *

class Window(QMainWindow):
    signal = Signal(str)

    def __init__(self, parent=None):
        super(Window, self).__init__(parent)
        self.button = QPushButton()
        self.button.setText("Test")
        self.setCentralWidget(self.button)
        self.button.clicked.connect(self.button_clicked)
        self.signal.connect(self.print_text)

    @Slot()
    def button_clicked(self):
        print('button clicked')
        self.signal.emit("It works!")

    @Slot(str)
    def print_text(self, text: str):
        print(text)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    app.exec_()
    sys.exit(0)
于 2013-08-13T02:42:51.703 回答