aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/signalmanager.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2025-05-14 10:18:45 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2025-05-16 15:03:44 +0200
commitc8dcf81d44e40afae2c6f03732cb9dfa82e51149 (patch)
treeccd6a1aa1072be31f27f9adfba442be396e4e3e8 /sources/pyside6/libpyside/signalmanager.cpp
parent760abafd4906d995ec5e149c5c0c88dbe571f90b (diff)
libpyside: Add a debug operator for PyObjectWrapper
This useful for debugging QML issues. Task-number: PYSIDE-2193 Pick-to: 6.9 Change-Id: Iecbfb1d9508ac89c8b213a2f2ee8d4f7f1de4fc8 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6/libpyside/signalmanager.cpp')
-rw-r--r--sources/pyside6/libpyside/signalmanager.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/sources/pyside6/libpyside/signalmanager.cpp b/sources/pyside6/libpyside/signalmanager.cpp
index e5f069c86..8b7b45546 100644
--- a/sources/pyside6/libpyside/signalmanager.cpp
+++ b/sources/pyside6/libpyside/signalmanager.cpp
@@ -26,6 +26,7 @@
#include <QtCore/qhash.h>
#include <QtCore/qscopedpointer.h>
+#include <climits>
#include <memory>
#include <utility>
@@ -233,7 +234,29 @@ QDataStream &operator>>(QDataStream &in, PyObjectWrapper &myObj)
return in;
}
-};
+PYSIDE_API QDebug operator<<(QDebug debug, const PyObjectWrapper &myObj)
+{
+ QDebugStateSaver saver(debug);
+ debug.noquote();
+ debug.nospace();
+ // Do not repeat the type name as it is typically called from the QVariant debug
+ // operator, which outputs the type.
+ debug << '<';
+ if (PyObject *ob = myObj) {
+ const auto refs = Py_REFCNT(ob);
+ debug << Py_TYPE(ob)->tp_name << " at " << ob;
+ if (refs == UINT_MAX) // _Py_IMMORTAL_REFCNT
+ debug << ", immortal";
+ else
+ debug << ", refs=" << refs;
+ } else {
+ debug << '0';
+ }
+ debug << '>';
+ return debug;
+}
+
+} // namespace PySide
using namespace PySide;