[PyQt] Pointer Attribute

Jay L. jlaura at asu.edu
Wed Oct 26 05:32:15 BST 2016


Made a bit more progress I think.  The below is building but crashing when
trying to convert from the Python Obj to a SiftPoint.

The %GetCode returns what I am expecting - a Python list of SiftPoint
objects.  The SiftPoint has been wrapped.  The %SetCode is seg. faulting on
sipConvertToType.

Within the %GetCode, I do not believe I have access to sipTransferObj or
sipIsErr.

Two questions:

1) Is this the intended use of %GetCode and %SetCode?  Should I be using
another directive?

2) In the SetCode block, how does one go about converting a list of class
instances into a C++ pointer?  Is this code heading down the right path?

Thanks!

    SiftPoint *h_data
    {
        %GetCode
            size_t size = sipCpp->numPts;
            PyObject *l = PyList_New(sipCpp->numPts);
            for (size_t i = 0; i < size; ++i){
                SiftPoint *sp = new SiftPoint(sipCpp->h_data[i]);
                PyObject *p = sipConvertFromType((void*)(sp),
sipType_SiftPoint, NULL);
                PyList_SetItem(l, i, p);
            }
            return l;
        %End

        %SetCode
        size_t length = PyList_GET_SIZE(sipPy);

        for (int i=0; i < length; ++i){

        if (!sipCanConvertToType(PyList_GET_ITEM(sipPy, i),
                                 sipType_SiftPoint, SIP_NOT_NONE))
            return 0;
        }

        printf("So far so good\n");
        sipCpp->numPts = length;

        // Set the length of the h_data
        SiftPoint h_data[length];
        sipCpp->h_data = h_data;

        for (size_t i=0; i < length; ++i){
            PyObject *sp  = PyList_GetItem(sipPy, i);

            SiftPoint *sif = reinterpret_cast<SiftPoint
*>(sipConvertToType(sp,

sipType_SiftPoint,

NULL,

SIP_NOT_NONE,

NULL, 0));
            h_data[i] = *sif;
        }
        %End

On Tue, Oct 25, 2016 at 6:32 AM, Jay L. <jlaura at asu.edu> wrote:

> Unfortunately, the sip error is non-specific.  It looks like what I
> actually need to use is %GetCode and %SetCode.
>
> Thanks!
>
> On Tue, Oct 25, 2016 at 12:56 AM, Phil Thompson <
> phil at riverbankcomputing.com> wrote:
>
>> On 24 Oct 2016, at 11:25 pm, Jay L. <jlaura at asu.edu> wrote:
>> >
>> > I have a class with an attribute that is a pointer:
>> >
>> > public:
>> >   SiftPoint *h_data
>> >
>> > I can write %MethodCode to expose a custom 'get_h_data()' method,  How
>> should I expose the attribute directly, e.g. my_py_class.h_data,
>> >
>> > I tried %MappedType, but am getting sip errors...
>>
>> ...then fix the sip errors.
>>
>> Phil
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161025/6f5d34ec/attachment.html>


More information about the PyQt mailing list