Merge pull request #195 from rcalixte/qt69_const

Qt 6.9: Return type for QObjectData_dynamicMetaObject is now const
This commit is contained in:
mappu 2025-04-11 19:15:14 +12:00 committed by GitHub
commit c2e299d381
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 54 additions and 2 deletions

View File

@ -651,6 +651,10 @@ func ApplyQuirks(className string, mm *CppMethod) {
mm.BecomesNonConstInVersion = addr("6.7")
}
if className == "QObjectData" && mm.MethodName == "dynamicMetaObject" {
mm.ReturnType.BecomesConstInVersion = addr("6.9")
}
if className == "QFileDialog" && mm.MethodName == "saveFileContent" && mm.IsStatic {
// The prototype was changed from
// [Qt 5 - 6.6] void QFileDialog::saveFileContent(const QByteArray &fileContent, const QString &fileNameHint = QString())

View File

@ -790,6 +790,14 @@ extern "C" {
`)
// We need this macro for QObjectData::dynamicMetaObject for Qt 6.9
if filename == "qobject.h" && packageName == "qt6" {
ret.WriteString("// Based on the macro from Qt (LGPL v3), see https://www.qt.io/qt-licensing\n" +
"// Macro is trivial and used here under fair use\n" +
"// Usage does not imply derivation\n" +
"#define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))\n\n")
}
foundTypesList := getReferencedTypes(src)
ret.WriteString("#ifdef __cplusplus\n")
@ -852,7 +860,16 @@ extern "C" {
continue // Can't call directly, have to go through our wrapper
}
ret.WriteString(fmt.Sprintf("%s %s(%s);\n", m.ReturnType.RenderTypeCabi(), cabiMethodName(c, m), emitParametersCabi(m, ifv(m.IsConst, "const ", "")+className+"*")))
if m.ReturnType.BecomesConstInVersion != nil && packageName == "qt6" {
ret.WriteString(fmt.Sprintf("// This method's return type was changed from non-const to const in Qt "+*m.ReturnType.BecomesConstInVersion) + "\n" +
"#if QT_VERSION >= QT_VERSION_CHECK(" + strings.Replace(*m.ReturnType.BecomesConstInVersion, `.`, `,`, -1) + ",0)\n" +
fmt.Sprintf("%s %s(%s);\n", "const "+m.ReturnType.RenderTypeCabi(), cabiMethodName(c, m), emitParametersCabi(m, ifv(m.IsConst, "const ", "")+className+"*")) +
"#else\n" +
fmt.Sprintf("%s %s(%s);\n", m.ReturnType.RenderTypeCabi(), cabiMethodName(c, m), emitParametersCabi(m, ifv(m.IsConst, "const ", "")+className+"*")) +
"#endif\n")
} else {
ret.WriteString(fmt.Sprintf("%s %s(%s);\n", m.ReturnType.RenderTypeCabi(), cabiMethodName(c, m), emitParametersCabi(m, ifv(m.IsConst, "const ", "")+className+"*")))
}
if m.IsSignal {
ret.WriteString(fmt.Sprintf("%s %s(%s* self, intptr_t slot);\n", m.ReturnType.RenderTypeCabi(), cabiConnectName(c, m), className))
@ -1249,6 +1266,20 @@ extern "C" {
"\n",
)
} else if m.ReturnType.BecomesConstInVersion != nil && strings.Contains(src.Filename, "qt6") {
ret.WriteString("" +
"// This method's return type was changed from non-const to const in Qt " + *m.ReturnType.BecomesConstInVersion + "\n" +
"#if QT_VERSION >= QT_VERSION_CHECK(" + strings.Replace(*m.ReturnType.BecomesConstInVersion, `.`, `,`, -1) + ",0)\n" +
"const " + m.ReturnType.RenderTypeCabi() + " " + methodPrefixName + "_" + m.SafeMethodName() + "(" + emitParametersCabi(m, ifv(m.IsConst, "const ", "")+methodPrefixName+"*") + ") {\n" +
"#else\n" +
m.ReturnType.RenderTypeCabi() + " " + methodPrefixName + "_" + m.SafeMethodName() + "(" + emitParametersCabi(m, ifv(m.IsConst, "const ", "")+methodPrefixName+"*") + ") {\n" +
"#endif\n" +
preamble + "\n" +
emitAssignCppToCabi("\treturn ", m.ReturnType, callTarget) +
"}\n\n",
)
} else {
ret.WriteString(fmt.Sprintf(

View File

@ -16,7 +16,8 @@ type CppParameter struct {
Optional bool
NoExcept bool
QtCppOriginalType *CppParameter // If we rewrote QStringList->QList<String>, this field contains the original QStringList. Otherwise, it's blank
QtCppOriginalType *CppParameter // If we rewrote QStringList->QList<String>, this field contains the original QStringList. Otherwise, it's blank
BecomesConstInVersion *string // "6,9"
}
func (p CppParameter) String() string {

View File

@ -36,7 +36,13 @@ void miqt_exec_callback_QObject_disconnectNotify(QObject*, intptr_t, QMetaMethod
} /* extern C */
#endif
// This method's return type was changed from non-const to const in Qt 6.9
#if QT_VERSION >= QT_VERSION_CHECK(6,9,0)
const QMetaObject* QObjectData_dynamicMetaObject(const QObjectData* self) {
#else
QMetaObject* QObjectData_dynamicMetaObject(const QObjectData* self) {
#endif
return self->dynamicMetaObject();
}

View File

@ -14,6 +14,11 @@
extern "C" {
#endif
// Based on the macro from Qt (LGPL v3), see https://www.qt.io/qt-licensing
// Macro is trivial and used here under fair use
// Usage does not imply derivation
#define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
#ifdef __cplusplus
class QAnyStringView;
class QBindingStorage;
@ -48,7 +53,12 @@ typedef struct QTimerEvent QTimerEvent;
typedef struct QVariant QVariant;
#endif
// This method's return type was changed from non-const to const in Qt 6.9
#if QT_VERSION >= QT_VERSION_CHECK(6,9,0)
const QMetaObject* QObjectData_dynamicMetaObject(const QObjectData* self);
#else
QMetaObject* QObjectData_dynamicMetaObject(const QObjectData* self);
#endif
void QObjectData_delete(QObjectData* self);
QObject* QObject_new();