QML Textinput
-
-
Hi Mohamed!
did you already read this doc?
http://doc-snapshot.qt-project.org/4.8/qtbinding.htmlits a good introduction about exchanging data between QML and C++!
Rgds, Steven
-
I suggest to derive your C++ class from QObject, and add that class to the Declaratice view.
@
MyClass myClass; // <-- Create your classQDeclarativeView view;
view.rootContext()->setContextProperty("myClass", &myClass); // <-- Add class to viewview.setSource(QUrl::fromLocalFile("MyQml.qml"));
view.show();
@Within your C++ class, create a slot that accepts a QString as parameter,
@
class MyClass : public QObject
{
Q_OBJECTpublic slots:
void cppSlot(const QString &value) {
qDebug() << "Called the C++ slot with value:" << value;
}
};
@from within QML, link your textinput to this slot
@
// MyItem.qml
import QtQuick 1.0TextInput {
id: item
width: 100; height: 20onAccepted: myClass.cppSLot(item.text)
}
@This is a quick draft, but i hope this would make it more clear !?
Rgrds, Steven
-
i guess :) thats how i do it...
Did you try it already this way?