From f61ba1b6d3b665af22e7f98af9031bf964a74a8b Mon Sep 17 00:00:00 2001 From: Ladislav Michl Date: Sat, 27 Jan 2024 23:57:37 +0100 Subject: [PATCH] Gui: Fix access via Python to QObject and QWidget --- src/Gui/PythonWrapper.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Gui/PythonWrapper.cpp b/src/Gui/PythonWrapper.cpp index a2ea77cffc36..9d2c4af5a717 100644 --- a/src/Gui/PythonWrapper.cpp +++ b/src/Gui/PythonWrapper.cpp @@ -677,7 +677,12 @@ Py::Object PythonWrapper::fromQObject(QObject* object, const char* className) throw Py::RuntimeError("Failed to wrap object"); #else // Access shiboken/PySide via Python - return qt_wrapInstance(object, className, "QtCore", "wrapInstance"); + std::string typeName; + if (className) + typeName = className; + else + typeName = object->metaObject()->className(); + return qt_wrapInstance(object, typeName, "QtCore", "wrapInstance"); #endif } @@ -699,7 +704,12 @@ Py::Object PythonWrapper::fromQWidget(QWidget* widget, const char* className) throw Py::RuntimeError("Failed to wrap widget"); #else // Access shiboken/PySide via Python - return qt_wrapInstance(widget, className, "QtWidgets", "wrapInstance"); + std::string typeName; + if (className) + typeName = className; + else + typeName = widget->metaObject()->className(); + return qt_wrapInstance(widget, typeName, "QtWidgets", "wrapInstance"); #endif }