[PyQt] SIP template

Rouzaud Denis denis.rouzaud at gmail.com
Tue May 16 20:49:57 BST 2017


Dear all,

I am facing an issue with correcty implementing a template (container)) in SIP.

Let’s say I have

qgsoptional:
template<class T>
class QgsOptional
{
  public:
    QgsOptional( const T &data, bool enabled )
      : mEnabled( enabled )
      , mData( data )
    {}
  private:
    bool mEnabled;
    T mData;
};

qgsoptionalexpression.h:

class QgsOptionalExpression : public QgsOptional<QgsExpression>
{
  public:
    QgsOptionalExpression();
}


Now, I’d like to create the SIP file for QgsOptioalExpression. I tried with what I found in another topic [0]:

class QgsOptionalExpression
{
%TypeHeaderCode
#include "qgsoptional.h"
typedef QgsOptional<QgsExpression> QgsOptionalExpression;
%End
  public:
    QgsOptionalExpression();
}

But this gives me this error:
python/core/qgsoptionalexpression.sip:29:36: error: typedef redefinition with different types ('QgsOptional' vs 'QgsOptionalExpression')
typedef QgsOptional QgsOptionalExpression;
The error points that the definition is already included in the header qgsoptionalepxression.h while I am actually not including it here (also gave it a try with including it).

I understand the point, but how shall I tackle this?
If I remove the inheritance, I’m of course not getting any of the container methods.
I also gave it a try with a ModuleHeaderCode:

 %ModuleHeaderCode
 #include "qgsoptional.h"
 #include "qgsexpression.h"
 typedef QgsOptional<QgsExpression> QgsOptionalExpression;
 %End

But it fails with the same kind of error, complaining the type is already defined in the header (also with or without including it in the TypeHeaderCode.


Any idea how to solve this?
Thanks a lot!

Denis


[0] https://www.riverbankcomputing.com/pipermail/pyqt/2015-May/035893.html <https://www.riverbankcomputing.com/pipermail/pyqt/2015-May/035893.html>




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170516/57565f45/attachment.html>


More information about the PyQt mailing list