on xenial help sign in
Make ApplicationArguments context property mockable from within QML code

I can mock a context property in QML by creating an QtObject whose id matches the context property name. But QML ids must begin with a lower case letter.

commit919e1969815ea35183ae5924b9055b7bd0a6b5f2 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateWed 24 Jul 2013, 09:08 (13 years ago) parent340b05f
2 files changed+3−3
Shell.qml+2−2 main.cpp+1−1
Shell.qml+2−2
@@ -36,8 +36,8 @@ FocusScope {
3636
3737 // this is only here to select the width / height of the window if not running fullscreen
3838 property bool tablet: false
39− width: tablet ? units.gu(160) : ApplicationArguments.hasGeometry() ? ApplicationArguments.width() : units.gu(40)
40− height: tablet ? units.gu(100) : ApplicationArguments.hasGeometry() ? ApplicationArguments.height() : units.gu(71)
39+ width: tablet ? units.gu(160) : applicationArguments.hasGeometry() ? applicationArguments.width() : units.gu(40)
40+ height: tablet ? units.gu(100) : applicationArguments.hasGeometry() ? applicationArguments.height() : units.gu(71)
4141
4242 property real edgeSize: units.gu(2)
4343 property url default_background: shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg"
main.cpp+1−1
@@ -113,7 +113,7 @@ int main(int argc, char** argv)
113113 view->setResizeMode(QQuickView::SizeRootObjectToView);
114114 view->setTitle("Qml Phone Shell");
115115 view->engine()->setBaseUrl(QUrl::fromLocalFile(::shellAppDirectory()));
116− view->rootContext()->setContextProperty("ApplicationArguments", &qmlArgs);
116+ view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
117117 if (args.contains(QLatin1String("-frameless"))) {
118118 view->setFlags(Qt::FramelessWindowHint);
119119 }