Problem with QMetaObject::invokeMethod
-
Hi,
i am not able to use the invokeMethod.
basically it is throwing me an ASSERT error in runtime.this is how i used it..
@void VoiceAnalyser::calculate(Accumulator buffer,
const QAudioFormat &format, QByteArray &playbackBuffer)
{
const bool b = QMetaObject::invokeMethod(m_thread, "calculateSpectrum",
Qt::AutoConnection,
Q_ARG(Accumulator, buffer),
Q_ARG(int, bytesPerSample),
Q_ARG(QByteArray, playbackBuffer));
Q_ASSERT(b);
}@but i am getting runtime error for assert..
pls tell me how to fix it..
thanx in advance. -
The documentation of QMetaObject::invokeMethod says:
bq. Invokes the member (a signal or a slot name) on the object obj. Returns true if the member could be invoked. Returns false if there is no such member or the parameters did not match.
So does "calculateSpectrum" exist on m_thread, are the parameters correct and are all the types used registered with the meta-type system (Accumulator)?
-
yes am having "calculatespectrum" on m_thread and all the parameters are correct...
but still not getting solution.. -
Your computer disagrees with that statement;-)
By the way: Why don't you just use have calculate emit a signal and properly connect that to the thread?
-
bq. Your computer disagrees with that statement;-)
sorry i did'nt get u.
bq. By the way: Why don’t you just use have calculate emit a signal and properly connect that to the thread?
i was thinking of that only but i dont know how to use that... on a thread...
can u pls help me with that..
-
A variation on this topic: Using Qt 5.1. and QtQuick.Controls 1.0
in QML: my ToolButton contains a simple function:
function setCurrentUser(userName) { text = userName; }
in C++:
setCurrentUser(const QString userName) {
if (!QMetaObject::invokeMethod(m_userButton, "setCurrentUser"
, Q_ARG(QVariant, userName))) { assert(false); }
}This works, as does a parameter-free version. But using a QString or int in the Q_ARG triggers the assert. The code samples (https://qt-project.org/doc/qt-5.0/qtcore/qmetaobject.html) clearly shows that QString or int can be used in the Q_ARG