Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. [shiboken2] Shared pointer support
Forum Updated to NodeBB v4.3 + New Features

[shiboken2] Shared pointer support

Scheduled Pinned Locked Moved Unsolved Qt for Python
qt for python
3 Posts 2 Posters 600 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adev
    wrote on last edited by adev
    #1

    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?

    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)
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Since it's on the shiboken level, I would recommend bringing your question to the PySide mailing list. You'll find there PySide2 developers/maintainers. This forum is more user oriented.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adev
        wrote on last edited by
        #3

        Thanks for answering - I did so :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved