[PySide] [shiboken2] Shared pointer support
icfwm at gmx.net
icfwm at gmx.net
Sat Jan 11 19:42:15 CET 2020
Hello,
I was redirected here from
https://forum.qt.io/topic/110539/shiboken2-shared-pointer-support. I
have a few questions regarding shared pointer support in shiboken2:
I want to wrap a library which is based on QT and which uses shared
pointers. I stumbled over a few issues, one of them seems to be a
showstopper:
*
It seems that wrapping classes which return shared pointers in a
virtual method is not possible at all. Non-virtual functions are
fine. The error from shiboken2 is "#error:
CppGenerator::writeVirtualMethodNative: B::genA(): Could not find a
minimal constructor for type 'QSharedPointer<A >'. This will result
in a compilation error.".
*
I'm not sure about what can be expected from the shared pointer
bridging. While I'm able to pass shared pointers which are generated
from the c++ side around in python, it seems to be impossible to
create a shared pointer from an object generated from the python side.
*
The documentation in shiboken regarding smart pointers seems to be
very limited. I couldn't figure out if setting "ref-count-method" is
required and why? For QSharedPointer, there doesn't seem to exist a
method for querying the reference count.
The first point looks like a shiboken2 bug to me and I'm wondering if
there are any workarounds here? I also created this issue here:
https://bugreports.qt.io/browse/PYSIDE-1188
Kind Regards
-------------------
Here are my test files:
test.h
|#ifndef TEST_H #define TEST_H #include <QtCore/QSharedPointer> // if
uncommented, you will get the following error when calling shiboken //
#error: CppGenerator::writeVirtualMethodNative: B::genA(): Could not
find a minimal constructor for type 'QSharedPointer<A >'. This will
result in a compilation error. #define SHIBOKEN_ERROR class A { public:
int a; A(int _a); virtual ~A(); }; class B { public: int b; B(int _b);
virtual ~B(); void doSomething(QSharedPointer<A> a); #ifdef
SHIBOKEN_ERROR virtual #endif QSharedPointer<A> genA(); }; #endif |
ptest.xml
|<!--?xml version="1.0"?--> <typesystem package="ptest">
<load-typesystem name="typesystem_core.xml" generate="no" />
<smart-pointer-type name="QSharedPointer" type="shared" getter="data" />
<object-type name="A" /> <object-type name="B" /> </typesystem> |
ptest .py
|import PySide2 import ptest a=ptest.A(1) b=ptest.B(2) a2=b.genA()
print(a2.a) b.doSomething(a2) # following is not working, need to create
a shared pointer from the python object a b.doSomething(a) |
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20200111/53696f36/attachment.html>
More information about the PySide
mailing list