Created
January 20, 2016 18:57
-
-
Save abali96/0bb2732c1c522c8d868a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QGuiApplication> | |
#include <QQmlApplicationEngine> | |
#include <QQmlComponent> | |
#include <QDebug> | |
#include <QQmlProperty> | |
#include <QQuickView> | |
//class MyClass : public QObject | |
//{ | |
// Q_OBJECT | |
// public slots: | |
void cppSlot(QString msg) { | |
qDebug() << "Called the C++ slot with message:" << msg; | |
} | |
//}; | |
//int main(int argc, char *argv[]) { | |
// QGuiApplication app(argc, argv); | |
// QQuickView view(QUrl::fromLocalFile("MyItem.qml")); | |
// QObject *item = view.rootObject(); | |
// MyClass myClass; | |
//QObject::connect(item, SIGNAL(qmlSignal(QString)), | |
// &myClass, SLOT(cppSlot(QString))); | |
// view.show(); | |
// return app.exec(); | |
//} | |
int main(int argc, char *argv[]) | |
{ | |
QGuiApplication app(argc, argv); | |
QQmlApplicationEngine engine; | |
QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/main.qml"))); | |
QObject *object = component.create(); | |
QObject::connect(object, SIGNAL(textSignal(QString)), void, SLOT(cppSlot(QString))); | |
// qDebug() << "Property value:" << QQmlProperty::read(object->children()[0], "text").toInt(); | |
// engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); | |
return app.exec(); | |
} | |
import QtQuick 2.5 | |
import QtQuick.Window 2.2 | |
Window { | |
visible: true | |
signal textSignal(string msg) | |
TextInput { | |
property string input: "" | |
property int number: 100 | |
id: textInput | |
text: "Enter your text here" | |
onAccepted: parent.textSignal("Hello from qml") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment