Skip to content

Commit

Permalink
Copy const attribute of method in QMetaObjectBuilder::addMethod()
Browse files Browse the repository at this point in the history
const attribute of prototype object method in
QMetaObjectBuilder::addMethod() is not copied. auto test failed due to
this missing functionality.

Copy const attribute of method in QMetaObjectBuilder::addMethod() from prototype object.

Task-number: QTBUG-126849
Change-Id: Iaa4042c2ac50c57eacb6b9821163488d82f7a0be
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
QtDheeru committed Dec 17, 2024
1 parent 7de17a9 commit f76c9bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/corelib/kernel/qmetaobjectbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QMetaMethod &prototype)
method.setAccess(prototype.access());
method.setAttributes(prototype.attributes());
method.setRevision(prototype.revision());
method.setConst(prototype.isConst());
return method;
}

Expand Down Expand Up @@ -1729,7 +1730,7 @@ void QMetaMethodBuilder::setAttributes(int value)
/*!
Returns true if the method is const qualified.
*/
int QMetaMethodBuilder::isConst() const
bool QMetaMethodBuilder::isConst() const
{
QMetaMethodBuilderPrivate *d = d_func();
if (!d)
Expand Down
2 changes: 1 addition & 1 deletion src/corelib/kernel/qmetaobjectbuilder_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class Q_CORE_EXPORT QMetaMethodBuilder
int attributes() const;
void setAttributes(int value);

int isConst() const;
bool isConst() const;
void setConst(bool methodIsConst=true);

int revision() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class SomethingOfEverything : public QObject
};
Q_DECLARE_FLAGS(SomethingFlag64, SomethingFlagEnum64)

Q_INVOKABLE Q_SCRIPTABLE void method1() {}
Q_INVOKABLE Q_SCRIPTABLE void method1() const {}

QString prop() const { return QString(); }
void setProp(const QString& v) { Q_UNUSED(v); }
Expand Down Expand Up @@ -219,6 +219,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(nullMethod.attributes(), 0);
QCOMPARE(nullMethod.revision(), 0);
QCOMPARE(nullMethod.index(), 0);
QCOMPARE(nullMethod.isConst(),0);

// Add a method and check its attributes.
QMetaMethodBuilder method1 = builder.addMethod("foo(const QString&, int)");
Expand All @@ -232,6 +233,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(method1.attributes(), 0);
QCOMPARE(method1.revision(), 0);
QCOMPARE(method1.index(), 0);
QCOMPARE(method1.isConst(),0);
QCOMPARE(builder.methodCount(), 1);

// Add another method and check again.
Expand Down Expand Up @@ -260,6 +262,7 @@ void tst_QMetaObjectBuilder::method()
method1.setAccess(QMetaMethod::Private);
method1.setAttributes(QMetaMethod::Cloned);
method1.setRevision(123);
method1.setConst(true);

// Check that method1 is changed, but method2 is not.
QCOMPARE(method1.signature(), QByteArray("foo(QString,int)"));
Expand All @@ -272,6 +275,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(method1.attributes(), QMetaMethod::Cloned);
QCOMPARE(method1.revision(), 123);
QCOMPARE(method1.index(), 0);
QCOMPARE(method1.isConst(),true);
QCOMPARE(method2.signature(), QByteArray("bar(QString)"));
QCOMPARE(method2.methodType(), QMetaMethod::Method);
QCOMPARE(method2.returnType(), QByteArray("int"));
Expand Down Expand Up @@ -303,6 +307,7 @@ void tst_QMetaObjectBuilder::method()
QCOMPARE(method1.attributes(), QMetaMethod::Cloned);
QCOMPARE(method1.revision(), 123);
QCOMPARE(method1.index(), 0);
QCOMPARE(method1.isConst(),true);
QCOMPARE(method2.signature(), QByteArray("bar(QString)"));
QCOMPARE(method2.methodType(), QMetaMethod::Method);
QCOMPARE(method2.returnType(), QByteArray("QString"));
Expand Down Expand Up @@ -356,6 +361,7 @@ void tst_QMetaObjectBuilder::slot()
QCOMPARE(method1.access(), QMetaMethod::Public);
QCOMPARE(method1.attributes(), 0);
QCOMPARE(method1.index(), 0);
QCOMPARE(method1.isConst(),0);
QCOMPARE(builder.methodCount(), 1);

// Add another slot and check again.
Expand Down Expand Up @@ -395,6 +401,7 @@ void tst_QMetaObjectBuilder::signal()
QCOMPARE(method1.access(), QMetaMethod::Public);
QCOMPARE(method1.attributes(), 0);
QCOMPARE(method1.index(), 0);
QCOMPARE(method1.isConst(),0);
QCOMPARE(builder.methodCount(), 1);

// Add another signal and check again.
Expand Down Expand Up @@ -1183,6 +1190,9 @@ static bool sameMethod(const QMetaMethod& method1, const QMetaMethod& method2)
if (method1.revision() != method2.revision())
return false;

if (method1.isConst() != method2.isConst())
return false;

return true;
}

Expand Down

0 comments on commit f76c9bf

Please sign in to comment.