1 #ifndef _PYTHONQTOBJECTPTR_H
2 #define _PYTHONQTOBJECTPTR_H
50 #include <QVariantList>
51 #include <QVariantMap>
68 :_object(p.takeObject()) {
102 _object = p.takeObject();
116 fromVariant(variant);
122 return object() == p.
object();
126 return !( *
this == p );
130 return object() == p;
134 return object() != p;
137 bool isNull()
const {
return !object(); }
153 QVariant
evalScript(
const QString& script,
int start = Py_file_input);
175 QVariant
call(
const QString& callable,
const QVariantList& args = QVariantList(),
const QVariantMap& kwargs = QVariantMap());
178 QVariant
call(
const QVariantList& args = QVariantList(),
const QVariantMap& kwargs = QVariantMap());
214 :_object(p._object) {
220 :_object(p.takeObject()) {
233 setObjectUnsafe(p.
object());
250 setObjectUnsafe(
nullptr);
252 _object = p.takeObject();
262 return object() == p.
object();
266 return !(*
this == p);
270 return object() == p;
274 return object() != p;
277 bool isNull()
const {
return !object(); }
a smart pointer that stores a PyObject pointer and that handles reference counting automatically
PythonQtObjectPtr & operator=(PythonQtObjectPtr &&p) noexcept
rvalue assignment operator that steals the reference from p
QVariant call(const QVariantList &args=QVariantList(), const QVariantMap &kwargs=QVariantMap())
call the contained python object directly, returns the result converted to a QVariant
PyObject * operator->() const
PythonQtObjectPtr(PythonQtObjectPtr &&p) noexcept
rvalue copy constructor, does not need any incref/decref.
void setObject(PyObject *o)
void addVariable(const QString &name, const QVariant &v)
add the given variable to the module
void evalFile(const QString &filename)
evaluates the given code in the context
PythonQtObjectPtr(PyObject *o)
PythonQtObjectPtr(const PythonQtObjectPtr &p)
PythonQtObjectPtr(PythonQtSafeObjectPtr &&p)
rvalue copy constructor, does not need any incref/decref.
QVariant toLocalVariant()
Returns a PythonQtObjectPtr as a QVariant. Only use this when you know that the variant is only used ...
bool operator==(PyObject *p) const
PyObject * object() const
PythonQtObjectPtr & operator=(PythonQtSafeObjectPtr &&p)
rvalue assignment operator that steals the reference from p
QVariant evalScript(const QString &script, int start=Py_file_input)
evaluates the given script code in the context of this object and returns the result value
void removeVariable(const QString &name)
remove the given variable
PythonQtObjectPtr(const QVariant &variant)
If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference...
QVariant toVariant()
Returns a PythonQtSafeObjectPtr as a QVariant. It does not return a PythonQtObjectPtr,...
PythonQtObjectPtr & operator=(const QVariant &variant)
PythonQtObjectPtr & operator=(const PythonQtObjectPtr &p)
void addObject(const QString &name, QObject *object)
add the given object to the module as a variable with name (it can be removed via clearVariable)
PyObject & operator*() const
bool fromVariant(const QVariant &variant)
If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference...
QVariant getVariable(const QString &name)
get the variable with the name of the module, returns an invalid QVariant on error
QVariant call(const QString &callable, const QVariantList &args=QVariantList(), const QVariantMap &kwargs=QVariantMap())
call the given python object (in the scope of the current object), returns the result converted to a ...
bool operator==(const PythonQtObjectPtr &p) const
QVariant evalCode(PyObject *pycode)
void setNewRef(PyObject *o)
sets the object and passes the ownership (stealing the reference, in Python slang)
PythonQtObjectPtr & operator=(PyObject *o)
a smart pointer that stores a PyObject pointer and that handles reference counting automatically
void setObject(PyObject *o)
PythonQtSafeObjectPtr & operator=(PyObject *o)
void setObjectUnsafe(PyObject *o)
PythonQtSafeObjectPtr(PythonQtSafeObjectPtr &&p) noexcept
rvalue copy constructor, does not need any incref/decref.
PythonQtSafeObjectPtr(const PythonQtSafeObjectPtr &p)
PyObject & operator*() const
PythonQtSafeObjectPtr & operator=(const PythonQtSafeObjectPtr &p)
PythonQtSafeObjectPtr(PyObject *o)
PythonQtSafeObjectPtr(PythonQtObjectPtr &&p)
rvalue copy constructor, does not need any incref/decref.
PythonQtSafeObjectPtr & operator=(const PythonQtObjectPtr &p)
PyObject * operator->() const
PythonQtSafeObjectPtr & operator=(PythonQtSafeObjectPtr &&p) noexcept
rvalue assignment operator that steals the reference from p
PyObject * object() const
bool operator==(PyObject *p) const
PythonQtSafeObjectPtr(const PythonQtObjectPtr &p)
PythonQtSafeObjectPtr & operator=(PythonQtObjectPtr &&p)
rvalue assignment operator that steals the reference from p
bool operator==(const PythonQtSafeObjectPtr &p) const