Menu

Bug fix: exposing enums on decorated objects

2010-10-11
2013-04-06
  • Chris Bevan

    Chris Bevan - 2010-10-11

    Hi all,

    I've been using PythonQt for a while now and have found it extremely useful.  Recently I've found and fixed a bug that you might be interested in.

    Exposing enums on objects works fine for me, as do decorators, but combining the two caused some problems.  Registering the decorator before the class, as seems to be the recommendation, means that the enums are initialised for a wrapper before the class' meta object is known.  This means the enum list ends up blank, and isn't regenerated, so the class' enums never appear.  Here's the fix:

    Modified: src/PythonQtClassInfo.cpp
    ===================================================================
    --- src/PythonQtClassInfo.cpp   2010-10-11 09:09:14 UTC (rev 28206)
    +++ src/PythonQtClassInfo.cpp   2010-10-11 09:23:19 UTC (rev 28207)
    @@ -839,6 +839,10 @@
     void PythonQtClassInfo::createEnumWrappers()
     {
       if (!_enumsCreated) {
    +    if (_meta == NULL) {
    +      // Don't create enums yet as the meta object is not set
    +      return;
    +    }
         _enumsCreated = true;
         if (_meta) {
           createEnumWrappers(_meta);
    

    Apologies if the line numbers for the diff are out slightly.  I've made a fair few other local changes for my project.

    Hope that's of some use to others too :)

    Cheers,

    - Chris

     
  • Chris Bevan

    Chris Bevan - 2010-10-22

    Hi again,

    I've additionally fixed a similar bug where looking up an enum on a class that hasn't been registered yet (e.g. a decorator for a class) causes an invalid parameter info to be cached.  This means that type matching or overload resolution can fail.

    The patch is a bit longer than the last one, and is unfortunately a bit hacky, so let me know if you're interested and I'll pass it on.

    Cheers,

    - Chris

     

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.