Skip to content

Instantly share code, notes, and snippets.

@abali96
Created January 20, 2016 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abali96/0bb2732c1c522c8d868a to your computer and use it in GitHub Desktop.
Save abali96/0bb2732c1c522c8d868a to your computer and use it in GitHub Desktop.
#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