[PyQt] Containers of pointers to MappedTypes
Nate Reid
gnatty7 at hotmail.com
Fri Feb 18 21:55:09 GMT 2011
I have a MappedType for std::string, and I wrote a test sip file that does conversion to and from a QList<std::string> and QList<std::string*> and I get compile errors with the auto-generated code based on the following stubs:
// SipStlTester.h
class SipStlTester
{
...
QList<std::string> listToListSP(const QList<std::string>
& input);
QList<std::string *> listToListSP(const QList<std::string *>
& input);
...
}
// SipStlTester.sip
%Module TestSTLTypes 0
%Import util.sip
%Import QtCore/QtCoremod.sip
class SipSTLTester
{
%TypeHeaderCode
#include "SipSTLTester.h"
%End
public:
SipSTLTester();
...
QList<std::string> listToListS (const
QList<std::string> & input);
QList<std::string *> listToListSP(const QList<std::string
*> & input);
...
};
Here is the autogenerated method for the function that fails: listToListSP
static PyObject *meth_SipSTLTester_listToListSP(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
const QList<std::string> * a0;
int a0State = 0;
SipSTLTester *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_SipSTLTester, &sipCpp, sipType_QList_0100std_string,&a0, &a0State))
{
QList<std::string> *sipRes;
Py_BEGIN_ALLOW_THREADS
sipRes = new QList<std::string>(sipCpp->listToListSP(*a0));
Py_END_ALLOW_THREADS
sipReleaseType(const_cast<QList<std::string> *>(a0),sipType_QList_0100std_string,a0State);
return sipConvertFromNewType(sipRes,sipType_QList_0100std_string,NULL);
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_SipSTLTester, sipName_listToListSP, NULL);
return NULL;
}
As you can see, it creates sipRes as a QList<std::string> rather than as the appropriate type of QList<std::string*>
std::string is a mapped type which the following definition:
%MappedType std::string
{
%TypeHeaderCode
#include <string>
%End
%ConvertFromTypeCode
if (!sipCpp) {
Py_INCREF(Py_None);
return Py_None;
}
// convert an std::string to a Python string
return PyString_FromString(sipCpp->c_str());
%End // ConvertFromTypeCode
%ConvertToTypeCode
if (sipIsErr == NULL) {
return PyString_Check(sipPy);
}
if (sipPy == Py_None) {
*sipCppPtr = new std::string;
return 1;
}
if (PyString_Check(sipPy)) {
*sipCppPtr = new std::string(PyString_AS_STRING(sipPy));
return 1;
}
return 0;
%End // ConvertToTypeCode
};
I am unable to make a mapped type for std::string* since that type of MappedType doesn't seem to be supported by SIP. So, in the MappedType for QList, there is one that _should_ support pointers to TYPE, e.g.
// QtCore/qlist.sip
// QList<TYPE *> is implemented as a Python list.
template<TYPE>
%MappedType QList<TYPE *> /DocType="list-of-TYPE"/
{
%TypeHeaderCode
#include <qlist.h>
%End
...
So, I would hope that it would autogenerate code for QList<std::string*> but SIP doesn't appear to be doing this.
I've verified this with Sip v. 4.10 and Sip 4.11.2
Thanks!
-Nate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110218/09c0b184/attachment-0001.html>
More information about the PyQt
mailing list