Pregunta

This is the code:

void invokeQMLFunction2Arg(QObject * object, QString func, QVariant p1, QVariant p2) {
    QMetaObject::invokeMethod(object, func, Qt::DirectConnection, Q_ARG(QVariant, p1), Q_ARG(QVariant, p2));
}

This is the error:

error: no matching function for call to 'QMetaObject::invokeMethod(QObject*&, QString&, Qt::ConnectionType, QArgument<QVariant>, QArgument<QVariant>)'

What am I missing? I call invokeMethod() with a pointer, yet the compiler complains it is a pointer reference.

¿Fue útil?

Solución

You are trying to pass a QString to the second argument, whereas that should be const char*. Convert that to the proper type because there is no implicit conversion. You need to decide which way to convert it to QByteArray first, so this is one example that you could potentially write:

QMetaObject::invokeMethod(object, func.toUtf8().constData(), Qt::DirectConnection, Q_ARG(QVariant, p1), Q_ARG(QVariant, p2));

Otros consejos

I have met with the same question. and My problem is actually cause by other factors. I move one of my program from QT 4 to QT 5, and I did not declare QDialog explicitly, so when I call the method, there is the error:

error: no matching function for call to 'QMetaObject::invokeMethod(QDialog*&, const char [12],     Qt::ConnectionType)'

and I see the compile output, the error message is,

note:   no known conversion for argument 1 from 'QDialog*' to 'QObject*'

suddenly, I realized that I do not declare the Qdialog. QT sometimes can not give a really good compile error output, I think.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top