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

List:       pykde
Subject:    Re: [PyQt] SIP template
From:       Denis Rouzaud <denis.rouzaud () gmail ! com>
Date:       2017-05-17 4:56:09
Message-ID: CAMtsY+aegh2UjB8Mw8a2kvZSno1-xzYWYVSUdfMtYLkKmrUi7w () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Davod,

Thanks a lot for you reply.

Le mar. 16 mai 2017 à 23:38, David Boddie <david@boddie.org.uk> a écrit :

> 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?
>
>
This compiles but I don't have access to enabled() and data() methods in
the template class (QgsOptional), which is a major issue.

With the inheritance written:
class QgsOptionalExpression : public QgOptional<QgsExpression>
I get a "syntax error".

Any idea?

Cheers,
Denis

[Attachment #5 (text/html)]

<div dir="ltr">Hi Davod,<div><br></div><div>Thanks a lot for you reply.<br><br><div \
class="gmail_quote"><div dir="ltr">Le  mar. 16 mai 2017 Ã   23:38, David Boddie \
&lt;<a href="mailto:david@boddie.org.uk">david@boddie.org.uk</a>&gt; a écrit  \
:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex">On Tue May 16 20:49:57 BST 2017, Denis Rouzaud \
wrote:<br> <br>
&gt; I am facing an issue with correcty implementing a template (container)) in<br>
&gt; SIP.<br>
&gt;<br>
&gt; Let's say I have<br>
&gt;<br>
&gt; qgsoptional:<br>
&gt; template&lt;class T&gt;<br>
&gt; class QgsOptional<br>
&gt; {<br>
&gt;     public:<br>
&gt;        QgsOptional( const T &amp;data, bool enabled )<br>
&gt;           : mEnabled( enabled )<br>
&gt;           , mData( data )<br>
&gt;        {}<br>
&gt;     private:<br>
&gt;        bool mEnabled;<br>
&gt;        T mData;<br>
&gt; };<br>
&gt;<br>
&gt; qgsoptionalexpression.h:<br>
&gt;<br>
&gt; class QgsOptionalExpression : public QgsOptional&lt;QgsExpression&gt;<br>
&gt; {<br>
&gt;     public:<br>
&gt;        QgsOptionalExpression();<br>
&gt; }<br>
<br>
OK, so you are defining a class called QgsOptionalExpression here. As far as<br>
I can see, this will conflict with what you are doing next:<br>
<br>
&gt; Now, I'd like to create the SIP file for QgsOptioalExpression. I tried with<br>
&gt; what I found in another topic [0]:<br>
&gt;<br>
&gt; class QgsOptionalExpression<br>
&gt; {<br>
&gt; %TypeHeaderCode<br>
&gt; #include &quot;qgsoptional.h&quot;<br>
&gt; typedef QgsOptional&lt;QgsExpression&gt; QgsOptionalExpression;<br>
&gt; %End<br>
&gt;     public:<br>
&gt;        QgsOptionalExpression();<br>
&gt; }<br>
<br>
Here, you define QgsOptionalExpression again using a typedef, resulting in<br>
the following error:<br>
<br>
&gt; But this gives me this error:<br>
&gt; python/core/qgsoptionalexpression.sip:29:36: error: typedef redefinition<br>
&gt; with different types (&#39;QgsOptional&#39; vs \
&#39;QgsOptionalExpression&#39;)<br> &gt; typedef QgsOptional \
QgsOptionalExpression;<br> &gt; The error points that the definition is already \
included in the header<br> &gt; qgsoptionalepxression.h while I am actually not \
including it here (also gave<br> &gt; it a try with including it).<br>
&gt;<br>
&gt; I understand the point, but how shall I tackle this?<br>
<br>
Good. :-) Just for others reading this, the reason for the conflict is that<br>
the typedef is included in the generated C++ code, so the compiler will<br>
encounter both the class definition and the typedef.<br>
<br>
If you don&#39;t need the class definition then remove it.<br>
<br>
If you do need it then I think you should be able to leave out the typedef<br>
and include the custom qgsoptionalexpression.h header instead:<br>
<br>
class QgsOptionalExpression<br>
{<br>
%TypeHeaderCode<br>
#include &quot;qgsoptionalexpression.h&quot;<br>
%End<br>
   public:<br>
      QgsOptionalExpression();<br>
}<br>
<br>
Does that help?<br><br></blockquote><div><br></div><div>This compiles but I don&#39;t \
have access to enabled() and data() methods in the template class (QgsOptional), \
which is a major issue.</div><div><br></div><div>With the inheritance written:  \
</div><div>class QgsOptionalExpression : public QgOptional&lt;QgsExpression&gt;  \
</div><div>I get a &quot;syntax error&quot;.</div><div><br></div><div>Any \
idea?</div><div><br></div><div>Cheers,</div><div>Denis</div><div><br></div><div>  \
</div></div></div></div>


[Attachment #6 (text/plain)]

_______________________________________________
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