How to send an array of integers from QML to C++? Can anyone fix this code such that ...
-
So I have a signal:
QML:
@signal qmlSendWorkflowIdsArraySignal(variant workflowIdsArray)@JS:
@sendToCppWorkflowIdsArray(arrayOfWorkflowIds);@C++:
@QObject::connect(qmlMainContentItemObject, SIGNAL(qmlSendWorkflowIdsArraySignal(QVariant)), &myController, SLOT(qmlToCppWorkflowIdsArraySlot(QVariant)));@then
@void qmlToCppWorkflowIdsArraySlot(QVariant workflowIdsArray)
{
qDebug() << " +++++++++++++++ Cpp Array slot has been called: "<<workflowIdsArray;
}@*Output: *
@+++++++++++++++ Cpp Array slot has been called:
QVariant(QVariantList, (QVariant(QString, "2") , QVariant(QString, "3") , QVariant(QString, "4") ) )@-
How do I read this QVariantList inside QVariant, ie, lets say I want to read this first element of the array, that is QVariant(QString, "2"), then the other and the other. This looks very complicated like this.
-
All I need is to pass an array of integers from QML to C++, so I can read this array.
-
I dont want to use QVariant or a QVariantList, unless I have to as I see no other way to do it.
Anyone any suggestion? Any professionals out there??
Thank you !!!!
-
-
I'm not sure I understand your question. I'd just use a QVariantList in your slot.
Also, using signals and slots to pass information is not the best idea. If it isn't an event, stick to using Q_INVOKABLE
-
[quote author="sohail" date="1418664714"]I'm not sure I understand your question. I'd just use a QVariantList in your slot.
Also, using signals and slots to pass information is not the best idea. If it isn't an event, stick to using Q_INVOKABLE[/quote]
-
How do I use Q_Invokable from qml? I am using Q_invokable to invoke JS methods from C++, but not the other way around.
-
If I use QVariantList, need to use QVariantList on the Signal from QML. Here QML:
@signal qmlSendWorkflowIdsArraySignal(variant workflowIdsArray)@
So basically I am sending workflowIdsArray, which I defined as type variant.
What is the syntax in QML to define a signal such that my workflowIdsArray is of type QVariantList?I have tried:
@signal qmlSendWorkflowIdsArraySignal( QVariantList workflowIdsArray);@But that is not a valid syntax.
-
-
Hi,
bq. How to send an array of integers from QML to C++?
Something like this:
@
//cpp
Q_INVOKABLE void setList(QVariantList arr) {
qDebug() << arr;
}//qml
property var arr: [1,5,7]Component.onCompleted: {
obj.setList(arr) //obj=contextproperty object
}
@