[PyQt] SIP 4.18.1 appears to be exposing private methods?

Elvis Stansvik elvstone at gmail.com
Thu Mar 9 07:45:46 GMT 2017


Den 9 mars 2017 8:40 fm skrev "Elvis Stansvik" <elvstone at gmail.com>:
>
> Den 9 mars 2017 8:11 fm skrev "Shaheed Haque" <srhaque at theiet.org>:
> >
> > Hi,
> >
> > I have come across some odd behaviour from SIP for a few of the files
> > I am generating such that SIP seems to be treating private methods as
> > if they were not private. For example, in one such case, the C++
> > header looks like this:
> >
> > /usr/include/KF5/AkonadiCore/tagmodel.h
> > ==============================
> > namespace Akonadi {
> > class TagModel: public QAbstractItemModel {
> > ...
> > Q_SIGNALS:
> >     void populated();
> >
> > private:
> >     bool insertRows(int row, int count, const QModelIndex &index =
> > QModelIndex()) Q_DECL_OVERRIDE;
> >     bool insertColumns(int column, int count, const QModelIndex &index
> > = QModelIndex()) Q_DECL_OVERRIDE;
> >     bool removeColumns(int column, int count, const QModelIndex &index
> > = QModelIndex()) Q_DECL_OVERRIDE;
> >     bool removeRows(int row, int count, const QModelIndex &index =
> > QModelIndex()) Q_DECL_OVERRIDE;
> > ...
> > };
> > ==============================
> >
> > And the SIP file says:
> >
> > ==============================
> > namespace Akonadi {
> > class TagModel: QAbstractItemModel {
> > ...
> >     Q_SIGNALS:
> >         void populated();
> >     private:
> >     private:
> >         // Generated for tagmodel.h, CLASS_DECL on line 36 'TagModel'
> > (by sip_generator.py:_container_get): non-copyable type handling
> >         TagModel(const Akonadi::TagModel &);
> >     };
> > };
> > ==============================
> >
> > Notice how the SIP does not contain the private member insertRows(),
> > e.g. after the populated() Q_SIGNAL. However, when I try to compile
> > the generated SIP, I see errors like this:
> >
> > ==============================
> > In file included from unifiedAkonadiCore.cpp:36:0:
> > tmp2/tmp/PyKF5/AkonadiCore/sipAkonadiCoreAkonadiTagModel.cpp: In
> > member function ‘virtual bool sipAkonadi_TagModel::insertRows(int,
> > int, const QModelIndex&)’:
> > tmp2/tmp/PyKF5/AkonadiCore/sipAkonadiCoreAkonadiTagModel.cpp:2564:54:
> > error: ‘virtual bool Akonadi::TagModel::insertRows(int, int, const
> > QModelIndex&)’ is private within this context
> > In file included from /usr/include/KF5/AkonadiCore/TagModel:1:0,
> >                  from tmp/AkonadiCore/TagModel.sip:28,
> >                  from unifiedAkonadiCore.cpp:8:
> > /usr/include/KF5/AkonadiCore/tagmodel.h:83:10: note: declared private
here
> >      bool insertRows(int row, int count, const QModelIndex &index =
> > QModelIndex()) Q_DECL_OVERRIDE;
> >           ^~~~~~~~~~
> > ===============================
> >
> > And sure enough, the generated class sipAkonadi_TagMode has a
> > protected member for insertRows() in the section commented "There is a
> > protected method for every virtual method...". Have I missed something
> > or is this a known issue?
>
> I've never used SIP, so this is just a guess, but maybe its confusion
comes from the fact that those methods are public in the base class, and
your class is publicly inheriting it? I would say it was probably a mistake
to declare them private?
>
> I'm not good enough with C++ to know what happens then, but I think that
(at least in C++11) if you want to make a public method private in the
subclass, you should use private: Base::fun();
>
> Not sure what is happening with SIP here though, Phil will have to answer.

My suspicion would be that some part of SIP's machinery thinks they are
public (which I think is what they are, being declared as such in the base
class), while another thinks they're private (because of the attempt to
hide them in the derived class). If so, then maybe there's room for
improvement in SIP to make it sort it out properly.

But this is just a guess :)

Elvis

>
> Cheers,
> Elvis
>
> >
> > Thanks, Shaheed
> > _______________________________________________
> > PyQt mailing list    PyQt at riverbankcomputing.com
> > https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170309/ff133008/attachment-0001.html>


More information about the PyQt mailing list