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

Alexander Bruy alexander.bruy at gmail.com
Tue Dec 11 10:56:51 GMT 2012


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
-- 
Alexander Bruy


More information about the PyQt mailing list