[PyQt] SIP multiple inheritance with template base class

Phil Thompson phil at riverbankcomputing.com
Tue Apr 3 15:35:05 BST 2018


On 3 Apr 2018, at 3:24 pm, Giuseppe Corbelli <corbelligiuseppe at mesdan.it> wrote:
> 
> On 03/31/2018 12:57 PM, Phil Thompson wrote:
>> On 30 Mar 2018, at 1:53 pm, Giuseppe Corbelli <corbelligiuseppe at mesdan.it> wrote:
>>> 
>>> Hi all
>>> for an ongoing project I am developing a Python interface for QCustomPlot.
>>> You can find it at https://github.com/cowo78/QCustomPlot-PyQt5/tree/v2.0.0
>>> 
>>> My first attempt with sip so look out for stupid mistakes.
>>> 
>>> SIP 4.19.8, (Py)Qt 5.9.2 on linux/gcc 7.3
>>> 
>>> I have the following hierarchy:
>>> 
>>> template <DataType>
>>> class QCPAbstractPlottable1D : public QCPAbstractPlottable, public QCPPlottableInterface1D /Abstract/
>>> {
>>> %TypeHeaderCode
>>> #include <QCustomPlot/src/qcp.h>
>>> #include "helper.h"
>>> %End
>>> { ... }
>>> 
>>> typedef QCPAbstractPlottable1D<QCPBarsData> QCPAbstractPlottable1D_QCPBarsData;
>>> 
>>> class QCPBars : public QCPAbstractPlottable1D_QCPBarsData
>>> {
>>> %TypeHeaderCode
>>> #include <QCustomPlot/src/qcp.h>
>>> 
>>> typedef QCPAbstractPlottable1D<QCPBarsData> QCPAbstractPlottable1D_QCPBarsData;
>>> %End
>>> ...
>>> }
>>> 
>>> Nevermind the helper.h include for a second. With this code the c++ generated for the QCPAbstractPlottable1D_QCPBarsData lacks a typedef.
>>> 
>>> The typedef'ed template specialization produces sipQCustomPlotQCPAbstractPlottable1D_QCPBarsData.cpp which references the typedef itself (QCPAbstractPlottable1D_QCPBarsData) but it is not copied in the generated file. The helper.h just works around the issue by providing the relevant typedef.
>>> 
>>> The full error can be reproduced by checking out branch v2.0.0 of https://github.com/cowo78/QCustomPlot-PyQt5.git and commenting out the #include "helper.h" directive.
>>> 
>>> Something wrong in my approach or an obscure bug somewhere?
>> I'm not sure what the issue is that you are raising. Is it the fact that you have to provide the C++ typedef (and, if you do, it works Ok)? If you specify something in the .sip file it is assumed that this reflects something that is in the C++ code - and you need to provide it if it doesn't.
> 
> Well, I must admit the explanation wasn't that good.
> The issue is that, even if I provide the typedefs, the generated code does not compile.

Sorry, still not clear. When you "provide the typedefs" do you mean in the .sip file or as a C++ typedef (possibly as handwritten code in the .sip file)?

> The generated code for the explicit template specialization does not include the relevant typedef.
> This is the compiler error:
> 
> sipQCustomPlotQCPAbstractPlottable1D_QCPBarsData.cpp:121:18: error: ‘QCPAbstractPlottable1D_QCPBarsData’ in namespace ‘::’ does not name a type
>         const  ::QCPAbstractPlottable1D_QCPBarsData *sipCpp;
> 
> Again, the error can be reproduced by checking out branch  v2.0.0 of https://github.com/cowo78/QCustomPlot-PyQt5.git and commenting out the #include "helper.h" directive in plottable1d.sip.

Please provide a short, complete example that demonstrates the problem.

Phil


More information about the PyQt mailing list