Menu

Exposing functions/slots at global scope

Help
2013-10-03
2013-10-06
  • Andrea Tagliasacchi

    Hello guys,
    right now I can register a Qt class with the python context as:

     PythonQt::self()->getMainModule().addObject("helper", (QObject*) my_object);
    

    What I do not like is that I have use "helper." every time:

     py >> helper.my_objec_slot()
    

    It'd be great if there was a way of defining a class whose methods were "globally exposed" in the pythonqt terminal. Something like this:

     PythonQt::self()->getMainModule().addObject("static", (QObject*) my_object);
    

    as it'd declared static, you are able to call the method directly:

    py >> my_object_slot()
    
     

    Last edit: Andrea Tagliasacchi 2013-10-03
  • Florian Link

    Florian Link - 2013-10-06

    PythonQt does not support this out of the box, but you can add your object with a special name, e.g. helper and then use the PythonQt introspection call to get all member names. The you can add them via addVariable(name, getVariable("helper." + name)).

     

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.