I have got a super class Common
, which inherits from QObject
. Then I have got a class Item
, which inherits from Common
.
Common.h
class Common : public QObject {
Q_OBJECT
public:
// some methods
};
Item.h
class Item : public Common {
Q_OBJECT
public:
// some methods
void test(QString value);
};
Item.cpp
void Item::test(QString value) {
qDebug() << value;
}
I want to use QMetaObject::invokeMethod
to dynamically call a function.
So I implemented a test function in the Item
class, which takes exactly one string.
Item* item = new Item();
QMetaObject::invokeMethod(item, "test", Qt::DirectConnection, Q_ARG(QString, "1234"));
This does not work. I get the following error: QMetaObject::invokeMethod: No such method Common::test(QString)
, which is perfectly okay and fine, because the Common
class has no test
function.
How can I tell QMetaObject::invokeMethod
, that it should call the method from the Item
class?