I had already found the link which have given sir.In this they are using javascript code but i am using C++.
Now i had tried anotherway of doing my app as:
I had made a function call to .cpp file and done the calcultion there and passed that value to the .qml file.
Here is my code:
.qml file
property string i;
property string c;
Button {
id: button1
x: 203
y: 258
text: “5â€
onClicked:
{
i = text t.text = t.text + i
}
}
Button {
id: button2
x: 203
y: 258
text: “3â€
onClicked: { i = text t.text = t.text + i
}
}
Button {
id: buttonplus
x: 136
y: 320
text: “+†onClicked: {
t.text = a;
t.text = b;
StringHelper.apple(a,b);
}
}
Button {
id: equal
x: 195
y: 320
width: 116
height: 42
text: “=â€
onClicked: {
t.text = StringHelper.apple(button1.text,button2.text);
}
}
TextField { id: t
x: 81
y: 60
width: 225
height: 50
text: ҠmaximumLength: 32765
}
property string i;
property string c;
Button {
id: button1
x: 203
y: 258
text: “5â€
onClicked:
{
i = text t.text = t.text + i
}
}
Button {
id: button2
x: 203
y: 258
text: “3â€
onClicked: { i = text t.text = t.text + i
}
}
Button {
id: buttonplus
x: 136
y: 320
text: “+†onClicked: {
t.text = a;
t.text = b;
StringHelper.apple(a,b);
}
}
Button {
id: equal
x: 195
y: 320
width: 116
height: 42
text: “=â€
onClicked: {
t.text = StringHelper.apple(button1.text,button2.text);
}
}
TextField { id: t
x: 81
y: 60
width: 225
height: 50
text: ҠmaximumLength: 32765
}
To copy to clipboard, switch view to plain text mode
stringhelper.h
#ifndef STRINGHELPER_H
#define STRINGHELPER_H
#include<QObject>
class StringHelper
: public QObject {
Q_OBJECT
public slots:
int apple(int a,int b)
{
int c = a + b;
return c;
}
};
#endif // STRINGHELPER_H
#ifndef STRINGHELPER_H
#define STRINGHELPER_H
#include<QObject>
class StringHelper : public QObject
{
Q_OBJECT
public slots:
int apple(int a,int b)
{
int c = a + b;
return c;
}
};
#endif // STRINGHELPER_H
To copy to clipboard, switch view to plain text mode
main.cpp:
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include "stringhelper.h"
#include<QDateTime>
int main(int argc, char *argv[])
{
StringHelper stringHelper;
QDeclarativeView view;
view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
view.rootContext()->setContextProperty("StringHelper", &stringHelper);
view.
setSource(QUrl("qml/sad/main.qml"));
#if defined(Q_WS_S60) || defined(Q_WS_MAEMO)
view.showMaximized();
#else
view.setGeometry(100, 100, 800, 480);
view.show();
#endif
return a.exec();
}
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include "stringhelper.h"
#include<QDateTime>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
StringHelper stringHelper;
QDeclarativeView view;
view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
view.rootContext()->setContextProperty("StringHelper", &stringHelper);
view.setSource(QUrl("qml/sad/main.qml"));
#if defined(Q_WS_S60) || defined(Q_WS_MAEMO)
view.showMaximized();
#else
view.setGeometry(100, 100, 800, 480);
view.show();
#endif
return a.exec();
}
To copy to clipboard, switch view to plain text mode
From this i was able to get the addition operation performed and displayed but in case if i am having 10 buttons with integers from 0-9 how to declare the result function:
in .qml file:
onClicked: {
t.text = StringHelper.apple(????????????????);
}
onClicked: {
t.text = StringHelper.apple(????????????????);
}
To copy to clipboard, switch view to plain text mode
???????
Could you please come out with a solution for my problem.....?
Bookmarks