Menu

Pass QObject to Python in QVariant?

2012-12-02
2013-04-06
  • Chris Meyer

    Chris Meyer - 2012-12-02

    If I want to pass a QObject derived class to Python via PythonQtObjectPtr::call(…), how do I do it?

    PythonQtObjectPtr::call takes a list of QVariants… but I don't see how to convert a QObject to a QVariant…?

    The web page http://pythonqt.sourceforge.net/Features.html says "Convenient conversions to/from QVariant for PythonQtObjectPtr" but I don't see how to do it.

    Any suggestions?

     
  • Florian Link

    Florian Link - 2012-12-02

    QObject* can be transported by QVariant, as follows:

    QObject* yourObjectPtr = whateverObjectPtr;
    QVariant arg = qVariantFromValue<QObject*>(yourObjectPtr)
    QVariantList args;
    args << arg;

    For details, google for qVariantFromValue or QVariant::fromValue.

     

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.