문제

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.

도움이 되었습니까?

해결책

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));

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top