SlideShare a Scribd company logo
1 of 15
Platform and device-specific settings for your QML layouts Artem Marchenko October 8, 2011 After Easy Discount Calculator by Artem Marchenko, JarmoParkkinen, TuukkaLindroos and Ekaterina Kuts Technical solution by Artem Marchenko and TuukkaLindroos
Artem Marchenko Product Manager, Agile Coach, QML engineer for hire Was a Product Manager shipping multi-hundred MEur products Three times Forum Nokia Champion Private entrepreneur Available for hire for all things QML http://fi.linkedin.com/in/artemmarchenko
Same app running on Harmattan, Android and Symbian
Easy Discount Calculator Symbian, MeeGo/Harmattan - http://store.ovi.com/content/186742 Android - http://bit.ly/discountcalculator Free, but has font issues on some models due to porting technology bug. Well working proof of concept for now
All the parameters can be fine-tuned on desktop
Settings system // SettingsBase.QML import Qt 4.7 import "GlobalSettings.js" as Js QtObject {     id: settingsObject // logical switches/conditions     property boolexitButtonPresent: true     property boolclearButtonIsBetweenTheLines: true     // element sizes     property introllerHeight: 110     property intdigitRollerWidth: 56     property intpercentageRollerWidth: digitRollerWidth
Settings system // SettingsMaemo.qml import Qt 4.7 SettingsBase {     property string platformTitle: "Maemo"     property intscreenWidthInPortrait:  480 ...     property introllerHeight: 160     property introllerNumberLineInnerSpacing:  0     property int digitRollerWidth:69 statusLineHeight: 0
Tree of settings
Using platform settings in JS //GlobalSettings.js .pragma library   // - the only QML possibility for global variables varglobalSettings = null // Will fetch the settings object from the item. If the settings object doesn't // exists, will return the global one or generate one on the fly based on base settings.  function getSettings(item) { …  if(item.settings) {         if(!globalSettings) { globalSettings = item.settings         } if(!globalSettings) { var component = Qt.createComponent("SettingsBase.qml") globalSettings = component.createObject(item)     }     return globalSettings;
Using Settings in QML // SmallButton.qml import Qt 4.7 import "GlobalSettings.js" as Js Rectangle {     id: button     width: Js.getSettings(button).smallButtonWidth     height: Js.getSettings(button).smallButtonHeight     radius: 3
Injecting Settings from C++ QStringsettingsPath = "qml/discountcalcui/Settings" + platformTitle + ".qml"; // localAdjustPath cares about platform-specific file location details settingsUrl = QUrl::fromLocalFile(CrossPlatformUtils::localAdjustPath(settingsPath)); QDeclarativeComponent component(view.engine(), settingsUrl); settingsInstance = component.create(); if(!settingsInstance) {           // No settings found - no object to install qWarning() << "Settings not found for this platform!"; qWarning() << component.errorString(); } else { settingsInstance->setProperty("shouldInitializeGlobalSettingWithItself", true); view.engine()->rootContext()->setContextProperty("forcedSettings”, settingsInstance);     } // continue with normal QML initialization
JavaScript side of initialization //SettingsBase.qml import Qt 4.7 import "GlobalSettings.js" as Js QtObject {     id: settingsObject     property boolshouldInitializeGlobalSettingWithItself: false // Is executed way before main QML file is loaded onShouldInitializeGlobalSettingWithItselfChanged: {         if(shouldInitializeGlobalSettingWithItself) { console.log("SBase: initializing global settings with " + settingsObject) Js.globalSettings = settingsObject         }     }
Switching settings for desktop simulation // Simulator for different platforms DiscountCalcUi {         id: main     } ListModel {         id: platformsModel ListElement {title: "Symbian"; visualTitle: "S^3"} ListElement{title: "Android480x800"; visualTitle: "Andr 800" } ListElement{title: "Harmattan" }     } onButtonClicked: { var component = Qt.createComponent("Settings" + model.title + ".qml") main.settings = component.createObject(main) } // actually, maybe we should have changed the global JS reference :/
Summary Parameterizing code everywhere is possible and easy Use JavaScript libraries for storing global objects To initialize settings by the moment of QML instantiations, inject settings from C++ before the main QML object Care about ability to change settings object for the desktop simulation of different platforms
Thank you Q&As time You can find these and similar slides at http://agilesoftwaredevelopment.com/tags/qml

More Related Content

Viewers also liked

Difference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam InsulationDifference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam InsulationBill Miller
 
Scrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básicoScrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básicoIgor Macaubas
 
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...Raj Lal
 
Vídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafiosVídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafiosIgor Macaubas
 
QML demo for makerpro (1)
QML demo for makerpro (1)QML demo for makerpro (1)
QML demo for makerpro (1)diro fan
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UIOpenBossa
 
Terraforming organisations
Terraforming organisationsTerraforming organisations
Terraforming organisationsClaudio Perrone
 
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...Raj Lal
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Nativeaccount inactive
 
Having the Correct Context for an Agile Transformation
Having the Correct Context for an Agile TransformationHaving the Correct Context for an Agile Transformation
Having the Correct Context for an Agile TransformationDerek Huether
 
Fases de RUP - PDF
Fases de RUP - PDFFases de RUP - PDF
Fases de RUP - PDFradoslawkb
 

Viewers also liked (19)

Difference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam InsulationDifference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam Insulation
 
Scrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básicoScrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básico
 
Resumen RUP
Resumen RUPResumen RUP
Resumen RUP
 
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
 
QtQuick Day 4
QtQuick Day 4QtQuick Day 4
QtQuick Day 4
 
Agile Contracts
Agile ContractsAgile Contracts
Agile Contracts
 
Vídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafiosVídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafios
 
QML demo for makerpro (1)
QML demo for makerpro (1)QML demo for makerpro (1)
QML demo for makerpro (1)
 
Hello, QML
Hello, QMLHello, QML
Hello, QML
 
QtQuick Day 2
QtQuick Day 2QtQuick Day 2
QtQuick Day 2
 
QtQuick Day 3
QtQuick Day 3QtQuick Day 3
QtQuick Day 3
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UI
 
Terraforming organisations
Terraforming organisationsTerraforming organisations
Terraforming organisations
 
Qt Qml
Qt QmlQt Qml
Qt Qml
 
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
 
QtQuick Day 1
QtQuick Day 1QtQuick Day 1
QtQuick Day 1
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Native
 
Having the Correct Context for an Agile Transformation
Having the Correct Context for an Agile TransformationHaving the Correct Context for an Agile Transformation
Having the Correct Context for an Agile Transformation
 
Fases de RUP - PDF
Fases de RUP - PDFFases de RUP - PDF
Fases de RUP - PDF
 

More from Artem Marchenko

One code Web, iOS, Android
One code Web, iOS, AndroidOne code Web, iOS, Android
One code Web, iOS, AndroidArtem Marchenko
 
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, FinlandArtem Marchenko
 
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, FinlandArtem Marchenko
 
Misapplied Scrum pattern
Misapplied Scrum patternMisapplied Scrum pattern
Misapplied Scrum patternArtem Marchenko
 
Effective Software Development for the 21st century
Effective Software Development for the 21st centuryEffective Software Development for the 21st century
Effective Software Development for the 21st centuryArtem Marchenko
 

More from Artem Marchenko (7)

One code Web, iOS, Android
One code Web, iOS, AndroidOne code Web, iOS, Android
One code Web, iOS, Android
 
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
 
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
 
Test driving-qml
Test driving-qmlTest driving-qml
Test driving-qml
 
Test driving QML
Test driving QMLTest driving QML
Test driving QML
 
Misapplied Scrum pattern
Misapplied Scrum patternMisapplied Scrum pattern
Misapplied Scrum pattern
 
Effective Software Development for the 21st century
Effective Software Development for the 21st centuryEffective Software Development for the 21st century
Effective Software Development for the 21st century
 

Recently uploaded

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governanceWSO2
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...caitlingebhard1
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingWSO2
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringWSO2
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 

QML settings

  • 1. Platform and device-specific settings for your QML layouts Artem Marchenko October 8, 2011 After Easy Discount Calculator by Artem Marchenko, JarmoParkkinen, TuukkaLindroos and Ekaterina Kuts Technical solution by Artem Marchenko and TuukkaLindroos
  • 2. Artem Marchenko Product Manager, Agile Coach, QML engineer for hire Was a Product Manager shipping multi-hundred MEur products Three times Forum Nokia Champion Private entrepreneur Available for hire for all things QML http://fi.linkedin.com/in/artemmarchenko
  • 3. Same app running on Harmattan, Android and Symbian
  • 4. Easy Discount Calculator Symbian, MeeGo/Harmattan - http://store.ovi.com/content/186742 Android - http://bit.ly/discountcalculator Free, but has font issues on some models due to porting technology bug. Well working proof of concept for now
  • 5. All the parameters can be fine-tuned on desktop
  • 6. Settings system // SettingsBase.QML import Qt 4.7 import "GlobalSettings.js" as Js QtObject { id: settingsObject // logical switches/conditions property boolexitButtonPresent: true property boolclearButtonIsBetweenTheLines: true // element sizes property introllerHeight: 110 property intdigitRollerWidth: 56 property intpercentageRollerWidth: digitRollerWidth
  • 7. Settings system // SettingsMaemo.qml import Qt 4.7 SettingsBase { property string platformTitle: "Maemo" property intscreenWidthInPortrait: 480 ... property introllerHeight: 160 property introllerNumberLineInnerSpacing: 0 property int digitRollerWidth:69 statusLineHeight: 0
  • 9. Using platform settings in JS //GlobalSettings.js .pragma library // - the only QML possibility for global variables varglobalSettings = null // Will fetch the settings object from the item. If the settings object doesn't // exists, will return the global one or generate one on the fly based on base settings. function getSettings(item) { … if(item.settings) { if(!globalSettings) { globalSettings = item.settings } if(!globalSettings) { var component = Qt.createComponent("SettingsBase.qml") globalSettings = component.createObject(item) } return globalSettings;
  • 10. Using Settings in QML // SmallButton.qml import Qt 4.7 import "GlobalSettings.js" as Js Rectangle { id: button width: Js.getSettings(button).smallButtonWidth height: Js.getSettings(button).smallButtonHeight radius: 3
  • 11. Injecting Settings from C++ QStringsettingsPath = "qml/discountcalcui/Settings" + platformTitle + ".qml"; // localAdjustPath cares about platform-specific file location details settingsUrl = QUrl::fromLocalFile(CrossPlatformUtils::localAdjustPath(settingsPath)); QDeclarativeComponent component(view.engine(), settingsUrl); settingsInstance = component.create(); if(!settingsInstance) { // No settings found - no object to install qWarning() << "Settings not found for this platform!"; qWarning() << component.errorString(); } else { settingsInstance->setProperty("shouldInitializeGlobalSettingWithItself", true); view.engine()->rootContext()->setContextProperty("forcedSettings”, settingsInstance); } // continue with normal QML initialization
  • 12. JavaScript side of initialization //SettingsBase.qml import Qt 4.7 import "GlobalSettings.js" as Js QtObject { id: settingsObject property boolshouldInitializeGlobalSettingWithItself: false // Is executed way before main QML file is loaded onShouldInitializeGlobalSettingWithItselfChanged: { if(shouldInitializeGlobalSettingWithItself) { console.log("SBase: initializing global settings with " + settingsObject) Js.globalSettings = settingsObject } }
  • 13. Switching settings for desktop simulation // Simulator for different platforms DiscountCalcUi { id: main } ListModel { id: platformsModel ListElement {title: "Symbian"; visualTitle: "S^3"} ListElement{title: "Android480x800"; visualTitle: "Andr 800" } ListElement{title: "Harmattan" } } onButtonClicked: { var component = Qt.createComponent("Settings" + model.title + ".qml") main.settings = component.createObject(main) } // actually, maybe we should have changed the global JS reference :/
  • 14. Summary Parameterizing code everywhere is possible and easy Use JavaScript libraries for storing global objects To initialize settings by the moment of QML instantiations, inject settings from C++ before the main QML object Care about ability to change settings object for the desktop simulation of different platforms
  • 15. Thank you Q&As time You can find these and similar slides at http://agilesoftwaredevelopment.com/tags/qml