moc: add a test for Q_FLAG getter/setter on integers
This is legacy behavior from Qt 3, before we had QFlags and before QVariant could support user types. I cannot find any instance of a getter returning an integer in current Qt or Qt Creator code. And note this only compiles if the flags type with Q_FLAG - not Q_ENUM. The content is wrapped as Qt 6.x only so it can be removed in Qt 7.0. The deprecation warning will come in a later commit, for 6.9. Change-Id: Ie3ddd8025e3b4387866efffd8e8d46c3daa0dff2 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit 939f7f56227e65c9797d17640a7b9c29166efc44) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
202acb9dc7
commit
c1b13a0c5f
@ -92,6 +92,10 @@ qt_internal_extend_target(tst_moc CONDITION CMAKE_CROSSCOMPILING
|
|||||||
MOC_CROSS_COMPILED
|
MOC_CROSS_COMPILED
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (${PROJECT_VERSION_MAJOR} LESS 7)
|
||||||
|
qt_internal_extend_target(tst_moc SOURCES flags-property-integer-access.h)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (UNIX AND (CLANG OR GCC OR QCC))
|
if (UNIX AND (CLANG OR GCC OR QCC))
|
||||||
qt_wrap_cpp(os9_moc os9-newlines.h)
|
qt_wrap_cpp(os9_moc os9-newlines.h)
|
||||||
endif()
|
endif()
|
||||||
|
23
tests/auto/tools/moc/flags-property-integer-access.h
Normal file
23
tests/auto/tools/moc/flags-property-integer-access.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2024 Intel Corporation.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||||
|
|
||||||
|
#ifndef FLAGS_PROPERTY_INTEGER_ACCESS
|
||||||
|
#define FLAGS_PROPERTY_INTEGER_ACCESS
|
||||||
|
#include <QtCore/qobject.h>
|
||||||
|
|
||||||
|
class ClassWithFlagsAccessAsInteger : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum Flag { F1 = 1, F2 = 2 };
|
||||||
|
Q_DECLARE_FLAGS(Flags, Flag)
|
||||||
|
Q_FLAG(Flags)
|
||||||
|
Q_PROPERTY(Flags flagsValue READ flagsValue WRITE setFlagsValue)
|
||||||
|
uint flagsValue() const { return f; }
|
||||||
|
void setFlagsValue(uint v) { f = v; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint f = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FLAGS_PROPERTY_INTEGER_ACCESS
|
@ -777,6 +777,9 @@ private slots:
|
|||||||
void uLongLong();
|
void uLongLong();
|
||||||
void inputFileNameWithDotsButNoExtension();
|
void inputFileNameWithDotsButNoExtension();
|
||||||
void userProperties();
|
void userProperties();
|
||||||
|
#if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0)
|
||||||
|
void integerAccessFlagsProperties();
|
||||||
|
#endif
|
||||||
void supportConstSignals();
|
void supportConstSignals();
|
||||||
void task87883();
|
void task87883();
|
||||||
void multilineComments();
|
void multilineComments();
|
||||||
@ -1077,6 +1080,25 @@ void tst_Moc::userProperties()
|
|||||||
QVERIFY(!property.isUser());
|
QVERIFY(!property.isUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0)
|
||||||
|
#include "flags-property-integer-access.h"
|
||||||
|
|
||||||
|
void tst_Moc::integerAccessFlagsProperties()
|
||||||
|
{
|
||||||
|
ClassWithFlagsAccessAsInteger o;
|
||||||
|
|
||||||
|
const QMetaObject *mobj = &ClassWithFlagsAccessAsInteger::staticMetaObject;
|
||||||
|
QMetaProperty property = mobj->property(mobj->indexOfProperty("flagsValue"));
|
||||||
|
QVERIFY(property.isValid());
|
||||||
|
QCOMPARE(property.metaType(), QMetaType::fromType<ClassWithFlagsAccessAsInteger::Flags>());
|
||||||
|
|
||||||
|
QVariant v = property.read(&o);
|
||||||
|
QCOMPARE(v, 0);
|
||||||
|
property.write(&o, QVariant::fromValue(ClassWithFlagsAccessAsInteger::F2));
|
||||||
|
QCOMPARE(o.flagsValue(), ClassWithFlagsAccessAsInteger::F2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void tst_Moc::supportConstSignals()
|
void tst_Moc::supportConstSignals()
|
||||||
{
|
{
|
||||||
QSignalSpy spy1(this, SIGNAL(constSignal1()));
|
QSignalSpy spy1(this, SIGNAL(constSignal1()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user