Menu

Calling a wrapped QObject method (slot) from a CPython module

Help
James
2013-06-27
2013-06-28
  • James

    James - 2013-06-27

    Hi,
    I have a QObject derived class with a slot declared:

    public slots:
    
    void foo(int size, void* data);
    

    When I add my object into the python interpreter with addObject() I can see the object and its method foo() from the PythonQt console. So far awesome! If do obj.foo.parameterTypes() I get back (('int', void*),) also great.

    Now I'm struggling trying to call this method with PyObject_CallMethod() from inside a c++ python module. I can't figure out the right thing to pass in for the void* argument.

    I could change the data argument to something else if that would simplify things. I just need to pass a pointer and I don't want to use strings because I don't want to make copies which I think PyObject_CallMethod will do if I use the "s#" conversion format.

    ta
    - James

     
  • Florian Link

    Florian Link - 2013-06-28

    AneasierwaytocallAn easier way to call Python objects from C++ is to use a

    PythonQtObjectPtr

    to wrap the Python object. Then you can simply use the call() method.

    Regarding the void argument, this is currently not supported,
    you can either use char
    or QString or QByteArray (or a pointer to a known object).

     
  • James

    James - 2013-06-28

    Thanks!

    Yes, the call() thing is great, I'm already making use of that elsewhere. I can't use that though in this situation though as I don't want the C module that I'm calling from depending on PythonQt.

    Passing void* is icky anyway I guess so I'm going to restructure the problem.

    This is a really cool library!

    Cheers,
    James

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.