Created
June 15, 2018 11:20
-
-
Save agateau-g/fddd17bf775bb043abd579bfb38a64a1 to your computer and use it in GitHub Desktop.
qmlflags
This file contains 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 <QDebug> | |
#include <QGuiApplication> | |
#include <QQmlApplicationEngine> | |
#include <QQmlContext> | |
class Foo : public QObject { | |
Q_OBJECT | |
public: | |
enum Ability { | |
NONE = 0, | |
RETRY = 1 << 0, | |
CANCEL = 1 << 1, | |
SHOW_PROGRESS = 1 << 2, | |
}; | |
Q_DECLARE_FLAGS(Abilities, Ability) | |
Q_FLAG(Abilities) | |
Q_INVOKABLE void echoFlags(Abilities flags) | |
{ | |
qDebug() << "flags" << flags; | |
} | |
}; | |
class Bar : public QObject { | |
Q_OBJECT | |
public: | |
Q_INVOKABLE void echoFlags(Foo::Abilities flags) | |
{ | |
qDebug() << "flags from bar" << flags; | |
} | |
}; | |
#include "main.moc" | |
int main(int argc, char* argv[]) | |
{ | |
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | |
QGuiApplication app(argc, argv); | |
qmlRegisterType<Foo>("foo", 1, 0, "Foo"); | |
qmlRegisterType<Bar>("foo", 1, 0, "Bar"); | |
Foo foo; | |
Bar bar; | |
QQmlApplicationEngine engine; | |
engine.rootContext()->setContextProperty("foo", &foo); | |
engine.rootContext()->setContextProperty("bar", &bar); | |
engine.load(QUrl(QStringLiteral("./main.qml"))); | |
if (engine.rootObjects().isEmpty()) | |
return -1; | |
return app.exec(); | |
} |
This file contains 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
import QtQuick 2.9 | |
import QtQuick.Controls 2.2 | |
import QtQuick.Window 2.2 | |
import foo 1.0 | |
ApplicationWindow { | |
id: window | |
visible: true | |
width: 640 | |
height: 480 | |
title: qsTr("Stack") | |
Button { | |
anchors.centerIn: parent | |
onClicked: { | |
foo.echoFlags(Foo.RETRY | Foo.CANCEL); | |
bar.echoFlags(Foo.RETRY | Foo.CANCEL); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment