diff options
author | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2015-05-11 12:52:34 +0200 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2015-05-13 12:08:54 +0000 |
commit | d6efc6b543d1a8fe2e1232750a98e396db07be0f (patch) | |
tree | f5a71f98a2c5e78814f9e293ded8a19d57c57a8a | |
parent | a4d66348d64368bfae10662a1f11a4e40eca8ae2 (diff) |
moc: Fix type for gadget's CreateInstance metacall
An error similar to the one below would be emitted
by the compiler on the moc generated file:
error: assigning to 'QObject *' from incompatible type 'Gadget *'
if (_a[0]) *reinterpret_cast<QObject**>(_a[0]) = _r; } break;
Change-Id: I75ae7bd6c46d20db2d47a80eaa08aae302d7d6c8
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r-- | src/tools/moc/generator.cpp | 3 | ||||
-rw-r--r-- | tests/auto/tools/moc/tst_moc.cpp | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index 8b6a0519c5..3b00e21208 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -1125,7 +1125,8 @@ void Generator::generateStaticMetacall() fprintf(out, "%s", QByteArray("QPrivateSignal()").constData()); } fprintf(out, ");\n"); - fprintf(out, " if (_a[0]) *reinterpret_cast<QObject**>(_a[0]) = _r; } break;\n"); + fprintf(out, " if (_a[0]) *reinterpret_cast<%s**>(_a[0]) = _r; } break;\n", + cdef->hasQGadget ? "void" : "QObject"); } fprintf(out, " default: break;\n"); fprintf(out, " }\n"); diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 405d273f4b..7fa5de3377 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -87,6 +87,16 @@ struct QTBUG_31218_Derived : QTBUG_31218<-1<0> {}; class QTBUG_45790 : Bug() { }; #endif +class CreatableGadget +{ + Q_GADGET + Q_PROPERTY(int a MEMBER a) +public: + Q_INVOKABLE CreatableGadget() : a(0xdeadbeef) { } + + int a; +}; + struct MyStruct {}; struct MyStruct2 {}; |