aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2019-11-13 19:12:16 +0100
committerChristian Tismer <tismer@stackless.com>2019-12-20 15:51:55 +0100
commit0b6dd91fbd02e4de1f653e2a8cd6e892628dac0c (patch)
tree05895f49ccc906fd291d8c1cf2d3ade96349f188
parentabeb6ecd702244a00be5666c55682211060ec6ea (diff)
qApp: Ensure QtCore import when embedded QApplication subclass is used
The qApp machinery works great with Python. When using embedding, things are different because there is no longer a wrapper layer. Unfortunately, many extension modules use C++ to derive a QApplication class. This has the side effect that when a foreign C++ module gets imported, the qApp machinery does not see it as it would in Python. Instead of a complex analysis, we always make sure that QtCore is imported. It will report the right instance, anyway. This change could not easily be tested. It was confirmed as a solution by Antonio Rojas. Change-Id: Ie9c56ac75e6c0ae3ace615dfc26c6d218ff4efea Fixes: PYSIDE-1135 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--sources/shiboken2/libshiboken/qapp_macro.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/sources/shiboken2/libshiboken/qapp_macro.cpp b/sources/shiboken2/libshiboken/qapp_macro.cpp
index 306f53b74..c2018bd6f 100644
--- a/sources/shiboken2/libshiboken/qapp_macro.cpp
+++ b/sources/shiboken2/libshiboken/qapp_macro.cpp
@@ -246,7 +246,14 @@ NotifyModuleForQApp(PyObject *module, void *qApp)
* qApp_contents variable and assigns the instance, instead of vice-versa.
*/
PyObject *coreDict = qApp_moduledicts[1];
- if (qApp != nullptr && coreDict != nullptr) {
+ if (coreDict == nullptr) {
+ // PYSIDE-1135: Make sure that at least QtCore gets imported.
+ // That problem exists when a derived instance is created in C++.
+ qApp_moduledicts[1] = Py_None; // anything != nullptr during import
+ coreDict = PyImport_ImportModule("PySide2.QtCore");
+ qApp_moduledicts[1] = coreDict;
+ }
+ if (qApp != nullptr && coreDict != nullptr && coreDict != Py_None) {
PyObject *coreApp = PyDict_GetItemString(coreDict, "QCoreApplication");
if (coreApp != nullptr) {
qApp_content = PyObject_CallMethod(coreApp, "instance", "");