diff --git a/sources/pyside6/libpyside/CMakeLists.txt b/sources/pyside6/libpyside/CMakeLists.txt
index 4c3aa25da..7fc27433e 100644
--- a/sources/pyside6/libpyside/CMakeLists.txt
+++ b/sources/pyside6/libpyside/CMakeLists.txt
@@ -23,6 +23,7 @@ set(libpyside_SRC
     qobjectconnect.cpp
 )
 
+set_source_files_properties (pysideqflags.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
 qt6_add_resources(libpyside_SRC libpyside.qrc)
 
 # Add python files to project explorer in Qt Creator, when opening the CMakeLists.txt as a project,
diff --git a/sources/pyside6/libpyside/dynamicqmetaobject.cpp b/sources/pyside6/libpyside/dynamicqmetaobject.cpp
index a3a16b6a0..c5ee93aee 100644
--- a/sources/pyside6/libpyside/dynamicqmetaobject.cpp
+++ b/sources/pyside6/libpyside/dynamicqmetaobject.cpp
@@ -654,11 +654,11 @@ void MetaObjectBuilderPrivate::parsePythonType(PyTypeObject *type)
     auto collectedEnums = PySide::QEnum::resolveDelayedQEnums(type);
     for (PyObject *obEnumType : collectedEnums) {
         bool isFlag = PySide::QEnum::isFlag(obEnumType);
-        AutoDecRef obName(PyObject_GetAttr(obEnumType, PyMagicName::name()));
+        AutoDecRef obName(PyObject_GetAttr(obEnumType, Shiboken::PyMagicName::name()));
         // Everything has been checked already in resolveDelayedQEnums.
         // Therefore, we don't need to error-check here again.
         auto name = String::toCString(obName);
-        AutoDecRef members(PyObject_GetAttr(obEnumType, PyMagicName::members()));
+        AutoDecRef members(PyObject_GetAttr(obEnumType, Shiboken::PyMagicName::members()));
         AutoDecRef items(PyMapping_Items(members));
         Py_ssize_t nr_items = PySequence_Length(items);
 
diff --git a/sources/pyside6/libpyside/pysideproperty.cpp b/sources/pyside6/libpyside/pysideproperty.cpp
index a4f90b8fd..d9be9393d 100644
--- a/sources/pyside6/libpyside/pysideproperty.cpp
+++ b/sources/pyside6/libpyside/pysideproperty.cpp
@@ -356,7 +356,7 @@ static PyObject *qPropertyDocGet(PyObject *self, void *)
         return PyUnicode_FromString(doc);
     if (pData->fget != nullptr) {
         // PYSIDE-1019: Fetch the default `__doc__` from fget. We do it late.
-        AutoDecRef get_doc(PyObject_GetAttr(pData->fget, PyMagicName::doc()));
+        AutoDecRef get_doc(PyObject_GetAttr(pData->fget, Shiboken::PyMagicName::doc()));
         if (!get_doc.isNull() && get_doc.object() != Py_None) {
             pData->doc = String::toCString(get_doc);
             pData->getter_doc = true;
@@ -368,7 +368,7 @@ static PyObject *qPropertyDocGet(PyObject *self, void *)
              * __doc__ in the class's dict.
              */
             auto get_doc_obj = get_doc.object();
-            int err = PyObject_SetAttr(self, PyMagicName::doc(), get_doc);
+            int err = PyObject_SetAttr(self, Shiboken::PyMagicName::doc(), get_doc);
             return err < 0 ? nullptr : (Py_INCREF(get_doc_obj), get_doc_obj);
         }
         PyErr_Clear();
diff --git a/sources/pyside6/libpyside/pysideqenum.cpp b/sources/pyside6/libpyside/pysideqenum.cpp
index 3f374b702..a612d5dcd 100644
--- a/sources/pyside6/libpyside/pysideqenum.cpp
+++ b/sources/pyside6/libpyside/pysideqenum.cpp
@@ -132,7 +132,7 @@ PyObject *QEnumMacro(PyObject *pyenum, bool flag)
     if (computedFlag < 0)
         return nullptr;
     if (bool(computedFlag) != flag) {
-        AutoDecRef name(PyObject_GetAttr(pyenum, PyMagicName::qualname()));
+        AutoDecRef name(PyObject_GetAttr(pyenum, Shiboken::PyMagicName::qualname()));
         auto cname = String::toCString(name);
         const char *e = "Enum";
         const char *f = "Flag";
diff --git a/sources/pyside6/libpyside/pysideslot.cpp b/sources/pyside6/libpyside/pysideslot.cpp
index 9fdfe489d..3ae594a6b 100644
--- a/sources/pyside6/libpyside/pysideslot.cpp
+++ b/sources/pyside6/libpyside/pysideslot.cpp
@@ -110,7 +110,7 @@ PyObject *slotCall(PyObject *self, PyObject *args, PyObject * /* kw */)
 
         if (data->slotData->name.isEmpty()) {
             // PYSIDE-198: Use PyObject_GetAttr instead of PepFunction_GetName to support Nuitka.
-            AutoDecRef funcName(PyObject_GetAttr(callback, PyMagicName::name()));
+            AutoDecRef funcName(PyObject_GetAttr(callback, Shiboken::PyMagicName::name()));
             data->slotData->name = funcName.isNull() ? "<no name>" : String::toCString(funcName);
         }
         const QByteArray returnType = QMetaObject::normalizedType(data->slotData->resultType);
diff --git a/sources/pyside6/libpysideqml/pysideqmlforeign.cpp b/sources/pyside6/libpysideqml/pysideqmlforeign.cpp
index 67aea1756..f9cc4f44d 100644
--- a/sources/pyside6/libpysideqml/pysideqmlforeign.cpp
+++ b/sources/pyside6/libpysideqml/pysideqmlforeign.cpp
@@ -73,7 +73,7 @@ PyTypeObject *PySideQmlForeign_TypeF(void)
 
 } // extern "C"
 
-static const char *qmlAttached_SignatureStrings[] = {
+static const char *qmlForeign_SignatureStrings[] = {
     "PySide6.QtQml.QmlForeign(self,type:type)",
     nullptr // Sentinel
 };
@@ -82,7 +82,7 @@ namespace PySide::Qml {
 
 void initQmlForeign(PyObject *module)
 {
-    if (InitSignatureStrings(PySideQmlForeign_TypeF(), qmlAttached_SignatureStrings) < 0)
+    if (InitSignatureStrings(PySideQmlForeign_TypeF(), qmlForeign_SignatureStrings) < 0)
         return;
 
     Py_INCREF(PySideQmlForeign_TypeF());
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index a1bb290e2..227f86038 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -72,31 +72,6 @@ const char *CppGenerator::PYTHON_TO_CPPCONVERSION_STRUCT = "Shiboken::Conversion
 
 static inline QString reprFunction() { return QStringLiteral("__repr__"); }
 
-static const char typeNameFunc[] = R"CPP(template <class T>
-static const char *typeNameOf(const T &t)
-{
-    const char *typeName =  typeid(t).name();
-    auto size = std::strlen(typeName);
-#if defined(Q_CC_MSVC) // MSVC: "class QPaintDevice * __ptr64"
-    if (auto lastStar = strchr(typeName, '*')) {
-        // MSVC: "class QPaintDevice * __ptr64"
-        while (*--lastStar == ' ') {
-        }
-        size = lastStar - typeName + 1;
-    }
-#else // g++, Clang: "QPaintDevice *" -> "P12QPaintDevice"
-    if (size > 2 && typeName[0] == 'P' && std::isdigit(typeName[1])) {
-        ++typeName;
-        --size;
-    }
-#endif
-    char *result = new char[size + 1];
-    result[size] = '\0';
-    memcpy(result, typeName, size);
-    return result;
-}
-)CPP";
-
 TextStream &operator<<(TextStream &s, CppGenerator::ErrorReturn r)
 {
     s << "return";
@@ -547,6 +522,7 @@ void CppGenerator::generateIncludes(TextStream &s, const GeneratorContext &class
             << "#include <feature_select.h>\n"
             << "QT_WARNING_DISABLE_DEPRECATED\n\n";
     }
+    s << "#include <typenameof.h>\n";
 
     // The multiple inheritance initialization function
     // needs the 'set' class from C++ STL.
@@ -686,8 +662,6 @@ void CppGenerator::generateClass(TextStream &s, const GeneratorContext &classCon
         }
     }
 
-    s  << '\n' << typeNameFunc << '\n';
-
     // class inject-code native/beginning
     if (!typeEntry->codeSnips().isEmpty()) {
         writeClassCodeSnips(s, typeEntry->codeSnips(),
@@ -971,8 +945,6 @@ void CppGenerator::generateSmartPointerClass(TextStream &s, const GeneratorConte
     IncludeGroup includes{u"Extra includes"_s, typeEntry->extraIncludes()};
     generateIncludes(s, classContext, {includes});
 
-    s  << '\n' << typeNameFunc << '\n';
-
     // Create string literal for smart pointer getter method.
     QString rawGetter = typeEntry->getter();
     s << "static const char " << SMART_POINTER_GETTER << "[] = \"" << rawGetter << "\";";
diff --git a/sources/shiboken6/libshiboken/CMakeLists.txt b/sources/shiboken6/libshiboken/CMakeLists.txt
index c788825a1..f7cefb9e6 100644
--- a/sources/shiboken6/libshiboken/CMakeLists.txt
+++ b/sources/shiboken6/libshiboken/CMakeLists.txt
@@ -164,6 +164,7 @@ install(FILES
         shiboken.h
         shibokenmacros.h
         threadstatesaver.h
+        typenameof.h
         shibokenbuffer.h
         sbkpython.h
         pep384impl.h
diff --git a/sources/shiboken6/libshiboken/typenameof.h b/sources/shiboken6/libshiboken/typenameof.h
new file mode 100644
index 000000000..af0544a2c
--- /dev/null
+++ b/sources/shiboken6/libshiboken/typenameof.h
@@ -0,0 +1,34 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#ifndef TYPENAMEOF_H
+#define TYPENAMEOF_H
+
+#include <cstring>
+#include <cctype>
+
+template <class T>
+static const char *typeNameOf(const T &t)
+{
+    const char *typeName =  typeid(t).name();
+    auto size = std::strlen(typeName);
+#if defined(Q_CC_MSVC) // MSVC: "class QPaintDevice * __ptr64"
+    if (auto lastStar = strchr(typeName, '*')) {
+        // MSVC: "class QPaintDevice * __ptr64"
+        while (*--lastStar == ' ') {
+        }
+        size = lastStar - typeName + 1;
+    }
+#else // g++, Clang: "QPaintDevice *" -> "P12QPaintDevice"
+    if (size > 2 && typeName[0] == 'P' && std::isdigit(typeName[1])) {
+        ++typeName;
+        --size;
+    }
+#endif
+    char *result = new char[size + 1];
+    result[size] = '\0';
+    memcpy(result, typeName, size);
+    return result;
+}
+
+#endif
