Menu

Using pythonHelpRequest()

Help
dparks
2010-05-01
2013-04-06
  • dparks

    dparks - 2010-05-01

    Hello,

    I have a question regarding how to use PythonQt::pythonHelpRequest (const QByteArray &cppClassName). I have this signal connected to a slot. Works like a charm. I'm a little lost at what I am suppose to do with just the object classname though. Is it possible to query the MetaObject system to get information about this class with just the classname? I'd essentially like to get the same information as provided by PythonQtClassInfo::help().

    It seems a little odd to me that the pythonHelpRequest() argument is the classname instead of a QString with the contents of PythonQtClassInfo::help() unless, as I suspect, there is something I can do with the classname.

    I'm new to the Qt MetaObject framework. Thanks for any and all help.

    Cheers,
    Donovan

     
  • Florian Link

    Florian Link - 2010-05-01

    Of course you could build the help string yourself from the QMetaObject information, but you are right, you can not get a QMetaObject from a string.

    You can use the following in the help slot:

    PythonQtClassInfo* info = PythonQt::priv()->getClassInfo(className);
    QString helpString = info->help()

    to get the string that is printed in Python (note the ->priv() instead of ->self(), since this is a somewhat private API).
    You could also ask the class info other things, like get a list of the members, follow the class hierarchy, etc.

    The main intention that I had in adding the redirection was to show completely different documentation,
    for instance in MeVisLab we show the docs for our own classes in an external HTML browser (generated from doxygen) and we show the original Qt docs for classes starting with Q*. For these cases, we only needed the classname.
    Probably passing PythonQtClassInfo would have been better, but as you can get the classinfo from the classname as seen above, I will leave it with the classname.

    And a sidenote:

    When embedding Python, it does not contain a built-in global help() function, this is added by the pyhon main executable…
    I added that myself in our product and directed it to the PythonQt help for classes that are of PythonQtWrapper_Type,
    since it is more common to call

    help(obj)

    then

    obj.help()

    (which PythonQt adds to it's objects).

    regards,
    Florian

     
  • dparks

    dparks - 2010-05-01

    Hello Florian,

    Thanks for the help! I am still a lost about one point though. I can indeed call PythonQt::priv()->getClassInfo(className) to get a PythonQtClassInfo object. However, the lib files don't seem to contain the implementation for this class. Specifically, I get the following compiler error (VS 9):

    error LNK2019: unresolved external symbol "public: char const * __thiscall PythonQtClassInfo::help(void)" (?className@PythonQtClassInfo@@QAEPBDXZ) referenced in function "public: void __thiscall PythonConsole::helpRequest(class QByteArray const &)" (?helpRequest@PythonConsole@@QAEXABVQByteArray@@@Z)

    I am linking against both PythonQt_d.lib and PythonQt_QtAll_d.lib. Things must be linking properly since I can compile the program when I comment out this line. This bring up a python console and I can use it as expected.

    By priv() being a "somewhat private API" did you mean that I would need to explicitly include PythonQtClassInfo.cpp in my project? I'm guessing not, so am hoping you might have some insight into this problem.

    Much thanks,
    Donovan

     
  • Florian Link

    Florian Link - 2010-05-02

    PythonQtClassInfo is not yet exported on the DLL interface, you need to add

    class PYTHONQT_EXPORT PythonQtClassInfo {

    to PythonQtClassInfo.h. Otherwise the class is not exported on Windows.
    Originally I thought to only expose the PythonQt main singleton,
    but I guess it makes sense to allow access to PythonQtClassInfo as well.
    I will add the exported class to the SVN repository as well.

    regards,
    Florian

     
  • dparks

    dparks - 2010-05-02

    Thanks Florian!

    I modified PythonQtClassInfo.h as you described and everything is now working like a charm.

    Cheers,
    Donovan

     

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.