How to call cpp file function from qml??
Hi All,
As i am new to qt quick i'm in need of calling a function from qml to cpp file, I am not able to write code for this. I tried this code...
I am trying to add two numbers!!!I tried writing it in qml but could not get the result.. so i am looking to write a function for adding the nos. in the cpp file .
i would call from qml to cpp function...
QML CODE:
Code:
property string i;
property string j;
Button {
id: one
x: 59
y: 131
width: 41
height: 42
text: "1"
onClicked:
{
i = text
textfield.text = textfield.text + i
}
}
Button {
id: two
x: 119
y: 131
text: "2"
onClicked:
{
i = text
textfield.text = textfield.text + i
}
}
Button {
id: add
x: 247
y: 131
text: "+"
onClicked:
{
j = textfield.text
ans = j
textfield.text = ""
funct.buttonclicked()
CPP CODE:
Code:
void funct::buttonclicked()
{
s->show();
.....???
.....???
}
I am not able write from this!!!!
Thanks in advance and Regards,
Naufal.A
Re: How to call cpp file function from qml??
Re: How to call cpp file function from qml??
Hi,
Can i have some more explanation on it sir.
I could not understand it clearly!!!!
Thanks and Regards,
Naufal.A
Re: How to call cpp file function from qml??
What's wrong with the examples from Qt docs on using context properties in QML?
Re: How to call cpp file function from qml??
Hi,
I am getting that cleared now.. i have one more doubt in this!!!
How to send the integer value from cpp fn to qml fn??
I have tried using QDeclarative view and also Qdeclarative context and i am getting only errors..
Error: cannot convert 'QGraphicsObject*' to 'QObject*' in initialization
QDeclarativeView view;
QObject *object = view.rootObject();
QObject* listView = object->findChild<QObject *>("events");
QVariant returnedValue;
QMetaObject::invokeMethod(listView, "addd",Q_RETURN_ARG(QVariant, returnedValue));
Can some one help me to find whats the mistake is
Thanks in advance and Regards,
Naufal.A
Re: How to call cpp file function from qml??
It's likely you are missing #include <QGraphicsObject>