[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] SIP template
From:       David Boddie <david () boddie ! org ! uk>
Date:       2017-05-16 21:37:07
Message-ID: 201705162337.08139.david () boddie ! org ! uk
[Download RAW message or body]

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
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic