[PyQt] SIP template
David Boddie
david at boddie.org.uk
Tue May 16 22:37:07 BST 2017
On Tue May 16 20:49:57 BST 2017, Denis Rouzaud wrote:
> 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();
> }
OK, so you are defining a class called QgsOptionalExpression here. As far as
I can see, this will conflict with what you are doing next:
> 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();
> }
Here, you define QgsOptionalExpression again using a typedef, resulting in
the following error:
> 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?
Good. :-) Just for others reading this, the reason for the conflict is that
the typedef is included in the generated C++ code, so the compiler will
encounter both the class definition and the typedef.
If you don't need the class definition then remove it.
If you do need it then I think you should be able to leave out the typedef
and include the custom qgsoptionalexpression.h header instead:
class QgsOptionalExpression
{
%TypeHeaderCode
#include "qgsoptionalexpression.h"
%End
public:
QgsOptionalExpression();
}
Does that help?
David
More information about the PyQt
mailing list