[PySide] QMetaObject::invokeMethod doesn't find the method

Peter Pan pelujamo at gmail.com
Tue Apr 22 10:55:34 CEST 2014


Hi,

I'm trying to understand how QMetaObject::invokeMethod can call a method of
an object with parameters (this object will later run in a different thread
and that will therefore come in handy). I'm failing so far. I also posted a
stackexchange question (
http://stackoverflow.com/questions/23127844/qmetaobjectinvokemethod-doesnt-find-the-method)
but no answers solved the full problem.

What works (calling a method without a parameter):

from PySide import QtCore

class Example(QtCore.QObject):
    def __init__(self):
        super().__init__()


    @QtCore.Slot()
    def beep(self):
        print('beep')

if __name__ == '__main__':
    t = Example()
    QtCore.QMetaObject.invokeMethod(t, 'beep', QtCore.Qt.AutoConnection)


What doesn't work is calling with a parameter. I tried:

from PySide import QtCore

class Example(QtCore.QObject):
    def __init__(self):

        super().__init__()

    @QtCore.Slot(str)
    def beep(self, text):
        print(text)

@QtCore.Slot(str)
def beep(text):
    print(text)

if __name__ == '__main__':
    t = Example()

    QtCore.QMetaObject.invokeMethod(t, 'beep', QtCore.Qt.AutoConnection,
QtCore.QGenericArgument('text', 'hello'))
    # or that but both fails
    QtCore.QMetaObject.invokeMethod(t, 'beep', QtCore.Qt.AutoConnection,
QtCore.QGenericArgument('self', t), QtCore.QGenericArgument('text',
'hello'))

and get the output
QMetaObject::invokeMethod: No such method Example::beep(text)
QMetaObject::invokeMethod: No such method Example::beep(self,text)

So how can I use QMetaObject::invokeMethod to invoke a method of a QObject
derived class with parameters? I use PySide 1.2.1 on Python 3.3 64 Bit on
Windows 7.

Cheers
Jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20140422/b200c103/attachment.html>


More information about the PySide mailing list