Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Q_ARG missing in python/ how to use invokeMethod ?
Forum Updated to NodeBB v4.3 + New Features

Q_ARG missing in python/ how to use invokeMethod ?

Scheduled Pinned Locked Moved Unsolved Qt for Python
11 Posts 7 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jim Gir
    wrote on last edited by
    #1

    Hi,
    I'm trying to use QMetaObject.invokeMethod wich needs some PySide2.QtCore.QGenericArgument wich has to be provided by the Q_ARG macro (https://doc.qt.io/qtforpython-5.12/PySide2/QtCore/QGenericArgument.html#PySide2.QtCore.QGenericArgument)

    Actually I can't find this Q_ARG macro in QtCore or anywhere else. where is it ?

    More generally how to use invokeMethod without it ?
    Jimmy

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jim Gir
      wrote on last edited by
      #2

      I already saw it.
      it import Q_ARG from QtCore but it doesn't exist in PySide2. I can't import it

      JonBJ 2 Replies Last reply
      0
      • J Jim Gir

        I already saw it.
        it import Q_ARG from QtCore but it doesn't exist in PySide2. I can't import it

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Jim-Gir
        Have you read e.g. https://stackoverflow.com/questions/23538904/qmetaobjectinvokemethod-doesnt-find-methods-with-parameters and other hits discussing this from Googling pyside2 q_arg?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Well, it looks like there's indeed something off here with Q_ARG, did you already check the bug report system ? If you don't find anything there please open a report providing a minimal runnable sample that reproduces the problem.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • J Jim Gir

            I already saw it.
            it import Q_ARG from QtCore but it doesn't exist in PySide2. I can't import it

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Jim-Gir
            I also meant to draw your attention to https://stackoverflow.com/questions/53296261/usage-of-qgenericargument-q-arg-when-using-invokemethod-in-pyside2. Which says there still isn't any Q_ARG in PySide2 and you can't do what you with no workaround :(

            As they point out in the answer that is a bug, it does not matter if it is QString or str, which still remains in PySide2 and unfortunately there is no workaround – eyllanesc Nov 14 '18 at 15:35

            1 Reply Last reply
            0
            • N Offline
              N Offline
              numaelisis
              wrote on last edited by
              #6

              someone reported the bug?
              the problem is from pyside qt4
              For the moment I resolved like this:

              in qml, file.qml:
              ApplicationWindow{
                id:root
                property var argsTemp
                Item{
                     id: myitem
                     objectName:"myitem"
               
                     function myFunctionBrige (){
                                 myFunction(argsTemp[0]);
                                 argsTemp=[];
                     }
               
                     function myFunction(arg){
                                console.log("myargLost",arg);
                     }
              }
              
              in python:
              engine.load(QUrl.fromLocalFile('file.qml'))
              root =  engine.rootObjects()[0]
              root.setProperty("argsTemp",["arg1"])
              object_qml = root.findChild(QObject, "myitem")
              QMetaObject.invokeMethod(object_qml, "myFunctionBrige")
              
              
              1 Reply Last reply
              0
              • I Offline
                I Offline
                ideaplus
                wrote on last edited by ideaplus
                #7

                Use pyqt5 instead of pyside2
                or Use signal slots instead of invokeMethod
                @Jim-Gir

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  numaelisis
                  wrote on last edited by
                  #8

                  but when are many functions? ...
                  and if you need to invoke from native code to qml?

                  using qt5 with c ++ no problem,
                  but PySide2, the Q_ARG macro is missing

                  JonBJ 1 Reply Last reply
                  0
                  • N numaelisis

                    but when are many functions? ...
                    and if you need to invoke from native code to qml?

                    using qt5 with c ++ no problem,
                    but PySide2, the Q_ARG macro is missing

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @numaelisis
                    Is this a question? Yes, PySide2 does not have any support for Q_ARG.

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      ideaplus
                      wrote on last edited by
                      #10

                      https://bugreports.qt.io/browse/PYSIDE-1262

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Alex Wilkinson
                        wrote on last edited by
                        #11

                        For myself, I came across this when trying to use an example written in PyQt5 and invokeMethod in PySide2.
                        The example was using invokeMethod to return a QImage from a separate thread that had done some processing.

                        An alternative solution that (with minimal testing) works is to create a signal object, and connect it to a slot via a queued connection.

                        from PySide2 import QtCore, QtGui
                        class MyClass(QtCore.QObject):
                           imageReady = QtCore.Signal(QtGui.QImage)
                        
                        
                          def __init__(self):
                           super()
                           self.imageReady.connect(self.setImage, QtCore.Qt.QueuedConnection)
                        
                          def processNewImageOnThread(image):
                             threading.Thread(target=self.process_image, args=(image)).start()
                        
                          def process_image(image):
                            # Process image here
                            self.imageReady.emit(image)
                        
                          @QtCore.Slot(QtGui.QImage)
                          def setZoomedImage(self, image):
                                # set this image on the viewmodel, which needs to be done on the GUI thread.
                                VM.zoomedImage = image
                        

                        I believe this example can be expanded to any set of arguments.

                        1 Reply Last reply
                        1

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved