I am doing a project with Qt where in invoke method runs on a seperate thread and called from main thread.
If I pass a QByteArray as const it builds and runs.
However if I remove the const it builds but terminates when I try to run it,
and throws an assert Q_ASSERT(b).
Why is it getting terminated?
I have to append some data into QByteArray.
const bool b = QMetaObject::invokeMethod(m_thread, "calculateSpectrum",
Qt::AutoConnection,
Q_ARG(QByteArray, buffer),
Q_ARG(int, format.frequency()),
Q_ARG(int, bytesPerSample),
Q_ARG(qint64, dataLength));
Q_ASSERT(b);
Q_UNUSED(b) // suppress warnings in release builds
basically the signature of QMetaobject::invokemethod is…
now in this we are using the Q_ARG macro whose syntax is..
which requires a const parameter.
Now when u remove this const parameter the condition becomes false and it will throw an assert at runtime.