How to receive a return value from python correctly? #318
Unanswered
ChenxiLiu-code
asked this question in
Q&A
Replies: 1 comment
-
This is somewhat expected. Objects in Python are reference-counted. If the reference count goes down to zero, the object is deleted. In the case of Python objects, the reference count is increased by the PythonQtObjectPtr stored in the QVariant. For the C++ object, there is no extra reference count. After the C++ object is returned from the evalScript method, the scope of the Python code is deleted, the reference count of the wrapper goes back zero, and the wrapper and its wrapped object are deleted. There are two things you can do:
I guess the first option is easier though. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
OS: Windows11 24H2
Python Version: 3.13
Qt Version: 6.8
PythonQt Version: 3.6
Compiler: msvc
I do two tests about receiving return value from python.
The first one is running well:
But if I change the TestPyObj Class to TestCppObj which is defined in Cpp code and registered to Python by PythonQt, the return value will be destroyed directly before the cpp code receive it. The Test Code is below
The printed messages are:
The class decleration is below:
Thanks for any help.
Beta Was this translation helpful? Give feedback.
All reactions