[PyQt] Wrap with SIP in-out string parameters in class method
Phil Thompson
phil at riverbankcomputing.com
Tue Dec 11 11:07:58 GMT 2012
On Tue, 11 Dec 2012 12:56:51 +0200, Alexander Bruy
<alexander.bruy at gmail.com> 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 );
> };
>
> I want to make username and password in-out parameters. With this file
> all compiled
> without any errors, but in runtime when I try to get username and
> password from Python
> I get
>
>>> res, u, p = AuthData.instance().get(myDbName, "", "")
>>>> print p
> Traceback (most recent call last):
> File "<input>", line 1, in <module>
> RuntimeError: underlying C/C++ object has been deleted
>
> Is it possible to implement such behaviour with SIP?
>
> I use Qt 4.8.2, SIP 4.13.2 and Python 2.7.3
>
>
> Thanks
Try passing QStrings as arguments rather than Python strings.
Phil
More information about the PyQt
mailing list