[PyQt] Wrap with SIP in-out string parameters in class method

Matt Newell newellm at blur.com
Tue Dec 11 17:51:19 GMT 2012


On Tuesday, December 11, 2012 02:56:51 AM Alexander Bruy wrote:
> Hi all,
> 
> I'm new to SIP and have some troubles with wrapping class in SIP.
> I need to declare some parameters as in and out.
> 
> Here is class header
> 
> class AuthData
> {
>   public:
>     virtual ~AuthData();
>     bool get( QString dbName, QString &username, QString &password,
> QString message = QString::null );
>     void put( QString dbName, QString username, QString password );
>     static AuthData *instance();
>   protected:
>     virtual bool request( QString dbName, QString &username, QString
> &password, QString message = QString::null ) = 0;
>     void setInstance( AuthData *theInstance );
>   private:
>     QMap< QString, QPair<QString, QString> > mAuthCache;
>     static AuthData *smInstance;
> };
> 
> And here is my sip file
> 
> class AuthData
> {
> %TypeHeaderCode
> #include <authdata.h>
> %End
> 
>   public:
>     virtual ~AuthData();
>     bool get( QString dbName, QString &username /In,Out/, QString
> &password /In,Out/, QString message = QString::null );
>     void put( QString dbName, QString username, QString password );
>     static AuthData *instance();
> 
>   protected:
>     virtual bool request( QString dbName, QString &username /In,Out/,
> QString &password /In,Out/, QString message = QString::null ) = 0;
>     void setInstance( QgsCredentials *theInstance );
> };
> 

You need to add the /Transfer/ annotation so that c++
has ownership and subsequent calls to instance() return a valid instance.

    void setInstance( AuthData * theInstance /Transfer/ ); 

Matt


More information about the PyQt mailing list