issue #0003984: Creating a Path Job object fails with 'PySide2.QtWidgets.QDialog' object has no attribute 'templateGroup'

This commit is contained in:
wmayer
2019-06-22 12:32:36 +02:00
parent 34402cbe90
commit d1e255f8d9

View File

@@ -232,6 +232,28 @@ Py::Object qt_wrapInstance(qttype object, const char* className,
return func.apply(arguments);
}
const char* qt_identifyType(QObject* ptr, const char* pyside)
{
PyObject* module = PyImport_ImportModule(pyside);
if (!module) {
std::string error = "Cannot load ";
error += pyside;
error += " module";
throw Py::Exception(PyExc_ImportError, error);
}
Py::Module qtmod(module);
const QMetaObject* metaObject = ptr->metaObject();
while (metaObject) {
const char* className = metaObject->className();
if (qtmod.getDict().hasKey(className))
return className;
metaObject = metaObject->superClass();
}
return nullptr;
}
void* qt_getCppPointer(const Py::Object& pyobject, const char* shiboken, const char* unwrap)
{
// https://github.com/PySide/Shiboken/blob/master/shibokenmodule/typesystem_shiboken.xml
@@ -475,7 +497,6 @@ bool PythonWrapper::loadWidgetsModule()
void PythonWrapper::createChildrenNameAttributes(PyObject* root, QObject* object)
{
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
Q_FOREACH (QObject* child, object->children()) {
const QByteArray name = child->objectName().toLocal8Bit();
@@ -484,19 +505,38 @@ void PythonWrapper::createChildrenNameAttributes(PyObject* root, QObject* object
if (!hasAttr) {
#if defined (HAVE_SHIBOKEN2) && defined(HAVE_PYSIDE2)
Shiboken::AutoDecRef pyChild(Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide2_QtCoreTypes[SBK_QOBJECT_IDX], child));
#else
Shiboken::AutoDecRef pyChild(Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], child));
#endif
PyObject_SetAttrString(root, name.constData(), pyChild);
#elif defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
Shiboken::AutoDecRef pyChild(Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], child));
PyObject_SetAttrString(root, name.constData(), pyChild);
#elif QT_VERSION >= 0x050000
const char* className = qt_identifyType(child, "PySide2.QtWidgets");
if (!className) {
if (qobject_cast<QWidget*>(child))
className = "QWidget";
else
className = "QObject";
}
Py::Object pyChild(qt_wrapInstance<QObject*>(child, className, "shiboken2", "PySide2.QtWidgets", "wrapInstance"));
PyObject_SetAttrString(root, name.constData(), pyChild.ptr());
#else
const char* className = qt_identifyType(child, "PySide.QtGui");
if (!className) {
if (qobject_cast<QWidget*>(child))
className = "QWidget";
else
className = "QObject";
}
Py::Object pyChild(qt_wrapInstance<QObject*>(child, className, "shiboken", "PySide.QtGui", "wrapInstance"));
PyObject_SetAttrString(root, name.constData(), pyChild.ptr());
#endif
}
createChildrenNameAttributes(root, child);
}
createChildrenNameAttributes(root, child);
}
#else
Q_UNUSED(root);
Q_UNUSED(object);
#endif
}
void PythonWrapper::setParent(PyObject* pyWdg, QObject* parent)