Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

PySide2 QMetaObject.invokeMethod() how to ?



  • Hey

    How to properly execute this command in python :

    QMetaObject::InvokeMethod(qApp,[=](){doSomeStuff();},Qt::QueuedConnection)

    TIA ?


  • Qt Champions 2019



  • @jsulm Hey, so would it be QMetaObject.InvokeMethod(QApplication.instance(), lambda (self.doSomeStuff()),Qt.QueuedConnection) ? Because all I get is lots of error I'm afraid...


  • Qt Champions 2019

    @Dariusz said in PySide2 QMetaObject.invokeMethod() how to ?:

    Because all I get is lots of error I'm afraid

    Which are?



  • @jsulm

    TypeError: 'PySide2.QtCore.QMetaObject.invokeMethod' called with wrong argument types:
      PySide2.QtCore.QMetaObject.invokeMethod(QApplication, function, ConnectionType)
    Supported signatures:
      PySide2.QtCore.QMetaObject.invokeMethod(PySide2.QtCore.QObject, bytes, PySide2.QtCore.Qt.ConnectionType, PySide2.QtCore.QGenericReturnArgument, PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ...)
      PySide2.QtCore.QMetaObject.invokeMethod(PySide2.QtCore.QObject, bytes, PySide2.QtCore.QGenericReturnArgument, PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ...)
      PySide2.QtCore.QMetaObject.invokeMethod(PySide2.QtCore.QObject, bytes, PySide2.QtCore.Qt.ConnectionType, PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ...)
      PySide2.QtCore.QMetaObject.invokeMethod(PySide2.QtCore.QObject, bytes, PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ..., PySide2.QtCore.QGenericArgument = ...)
    

    :- )


  • Qt Champions 2019

    @Dariusz Why do you want to call lambda using invokeMethod?
    As the name suggests invokeMethod is used to call a method of a class on an instance of that class. A lambda is not a method of QApplication...



  • @jsulm Well as the example in 1st post shows, I was creating a function in c++ to be called. I want the same to do in python. Simply put, I want to create temporary function that gets send to qapplication from 3rd party thread to be executed inside qt event loop.


  • Qt Champions 2019

    @Dariusz If you check the PySide documentation you will see that there is no overload taking a lambda or any function/method. There are only overloads accepting strings containing method name. So, it seems not possible with PySide.
    But instead of using QApplication instance you could create your own class with methods you want to call using invokeMethod.