Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Super simple example of using Q_PROPERTY to integrate C++ data with QML

  • Loading branch information...
commit 31483736a3aa80082ab9f44c6ed6ef6aeae3ac99 1 parent ee28a9f
Martin Woolley authored
204 PropertyExample/LICENSE
View
@@ -0,0 +1,204 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-------------------------------------------------------
+Copyright 2012 BlackBerry Limited.
6 PropertyExample/Makefile
View
@@ -0,0 +1,6 @@
+QMAKE_TARGET = PropertyExample
+PROJECT_DIR := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
+I18N_DIR := $(PROJECT_DIR)/translations
+
+include mk/cs-base.mk
+
5 PropertyExample/PropertyExample.pro
View
@@ -0,0 +1,5 @@
+APP_NAME = PropertyExample
+
+CONFIG += qt warn_on cascades10
+
+include(config.pri)
55 PropertyExample/README.md
View
@@ -0,0 +1,55 @@
+# PropertyExample
+
+The purpose of this application is to demonstrate in as simple an appliation as possible, the Qt property system that allows the integration of C++ data with QML.
+
+The sample code for this application is Open Source under
+the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html).
+
+**Applies To**
+
+* [Cascades for BlackBerry 10](https://bdsc.webapps.blackberry.com/cascades/)
+
+**Author(s)**
+
+* [Martin Woolley](https://github.com/mdwoolley)
+
+**Release History**
+
+* **V1.0.0** - INitial release
+
+**Known Issues**
+
+None.
+
+**Dependencies**
+
+1. BlackBerry Dev Alpha Beta 3 Device Software **10.2.0**
+
+**How to Build PropertyExample**
+
+Simply Import the project into a workspace in your NDK.
+
+**To contribute code to this repository you must be [signed up as an
+official contributor](http://blackberry.github.com/howToContribute.html).**
+
+## Contributing Changes
+
+Please see the [README](https://github.com/blackberry/Cascades-Community-Samples/blob/master/README.md) of the Cascades-Community-Samples repository for instructions on how to add new Samples or
+make modifications to existing Samples.
+
+## Bug Reporting and Feature Requests
+
+If you find a bug in a Sample, or have an enhancement request, simply file
+an [Issue](https://github.com/blackberry/Cascades-Community-Samples/issues) for
+the Sample and send a message (via github messages) to the Sample Author(s) to let
+them know that you have filed an [Issue](https://github.com/blackberry/Cascades-Community-Samples/issues).
+
+
+## Disclaimer
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
6 PropertyExample/assets/.assets.index
View
@@ -0,0 +1,6 @@
+1
+4
+AboutSheet.qml
+images/about.png
+images/ic_previous.png
+main.qml
102 PropertyExample/assets/AboutSheet.qml
View
@@ -0,0 +1,102 @@
+/* Copyright (c) 2013 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import bb.cascades 1.0
+
+Sheet {
+ id: root
+
+ Page {
+ Container {
+ layout: StackLayout {
+ }
+ verticalAlignment: VerticalAlignment.Fill
+ Label {
+ id: lblHeading_about
+ text: qsTr("About PropertyExample")
+ textStyle {
+ base: SystemDefaults.TextStyles.BigText
+ }
+ verticalAlignment: VerticalAlignment.Center
+ horizontalAlignment: HorizontalAlignment.Center
+ }
+ Label {
+ id: lblHeading_version
+ text: qsTr("V1.0.0")
+ verticalAlignment: VerticalAlignment.Center
+ horizontalAlignment: HorizontalAlignment.Center
+ }
+ Label {
+ id: lblBody_about
+ text: qsTr("The PropertyExample application demonstrates how to use the Q_PROPERTY macro to integrate C++ resident data with QML in as simple a context as possible")
+ multiline: true
+ textStyle {
+ base: SystemDefaults.TextStyles.BodyText
+ fontFamily: "Courier"
+ lineHeight: 1.1
+ }
+ }
+ Label {
+ id: lblAuthors
+ text: qsTr("Author:")
+ multiline: true
+ textStyle {
+ base: SystemDefaults.TextStyles.BodyText
+ fontFamily: "Courier"
+ lineHeight: 1.1
+ }
+ }
+ Label {
+ id: lblAuthors1
+ text: qsTr("Martin Woolley (@mdwrim)")
+ multiline: true
+ textStyle {
+ base: SystemDefaults.TextStyles.BodyText
+ fontFamily: "Courier"
+ lineHeight: 1.1
+ }
+ }
+ }
+ actions: [
+ ActionItem {
+ title: "Back"
+ imageSource: "asset:///images/ic_previous.png"
+ ActionBar.placement: ActionBarPlacement.OnBar
+ onTriggered: {
+ root.close();
+ }
+ },
+ InvokeActionItem {
+ id: shareMe
+ ActionBar.placement: ActionBarPlacement.OnBar
+ query {
+ mimeType: "text/plain"
+ invokeActionId: "bb.action.SHARE"
+ onQueryChanged: {
+ shareMe.query.updateQuery();
+ }
+ }
+ handler: InvokeHandler {
+ id: shareHandler
+ onInvoking: {
+ shareMe.data = "Check out the #BlackBerry10 'PropertyExample' " + "Sample App on Git Hub written by @mdwrim " + "here http://bit.ly/SJBBKl";
+ shareHandler.confirm();
+ }
+ }
+ }
+ ]
+ }
+}
+
BIN  PropertyExample/assets/images/about.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  PropertyExample/assets/images/ic_previous.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 PropertyExample/assets/main.qml
View
@@ -0,0 +1,101 @@
+
+/* Copyright (c) 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import bb.cascades 1.2
+
+Page {
+
+ function logMessage(message) {
+ log.text += (qsTr("\n") + message );
+ }
+
+ Container {
+ layout: StackLayout {
+ }
+
+ horizontalAlignment: HorizontalAlignment.Fill
+ verticalAlignment: VerticalAlignment.Fill
+
+ Label {
+ text: qsTr("PropertyExample")
+ textStyle {
+ base: SystemDefaults.TextStyles.BigText
+ }
+ verticalAlignment: VerticalAlignment.Center
+ horizontalAlignment: HorizontalAlignment.Center
+ }
+
+ TextField {
+ id: tf
+ objectName: "tf"
+ // this causes the READ method bound to our property to be called
+ text: my_prop.my_property
+ }
+ Button {
+ text: "Change Property"
+ horizontalAlignment: HorizontalAlignment.Fill
+ onClicked: {
+ // this causes the WRITE method bound to our property to be called
+ my_prop.my_property = tf.text
+ }
+ }
+ Button {
+ text: "Reset"
+ horizontalAlignment: HorizontalAlignment.Fill
+ onClicked: {
+ // this calls a C++ method that was exposed using Q_INVOKABLE
+ my_prop.resetMyProperty();
+ }
+ }
+
+ ScrollView {
+ id: logScroller
+ horizontalAlignment: HorizontalAlignment.Fill
+ verticalAlignment: VerticalAlignment.Fill
+ TextArea {
+ id: log
+ text: ""
+ editable: false
+ textStyle {
+ base: SystemDefaults.TextStyles.BodyText
+ color: Color.Green
+ fontFamily: "Courier"
+ lineHeight: 1.1
+ }
+ onTextChanged: {
+ logScroller.scrollToPoint(0, Infinity);
+ }
+ }
+ }
+ }
+
+ actions: [
+ ActionItem {
+ title: qsTr("About")
+ imageSource: "asset:///images/about.png"
+ onTriggered: {
+ aboutInfo.open();
+ }
+ }
+ ]
+
+ attachedObjects: [
+ AboutSheet {
+ id: aboutInfo
+ }
+ ]
+
+}
100 PropertyExample/bar-descriptor.xml
View
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!--
+
+ Copyright (c) 2011, 2012, 2013 Research In Motion Limited.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<qnx xmlns="http://www.qnx.com/schemas/application/1.0">
+
+<!-- BlackBerry 10 application descriptor file.
+
+ Specifies parameters for identifying, installing, and launching native applications on BlackBerry 10.
+
+-->
+
+ <!-- A universally unique application identifier. Must be unique across all BlackBerry 10 applications.
+ Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required. -->
+ <id>com.example.PropertyExample</id>
+
+ <!-- The name that is displayed in the BlackBerry 10 application installer.
+ May have multiple values for each language. See samples or xsd schema file. Optional. -->
+ <name>PropertyExample</name>
+
+ <!-- A string value of the format <0-999>.<0-999>.<0-999> that represents application version which can be used to check for application upgrade.
+ Values can also be 1-part or 2-part. It is not necessary to have a 3-part value.
+ An updated version of application must have a versionNumber value higher than the previous version. Required. -->
+ <versionNumber>1.0.0</versionNumber>
+
+ <!-- Fourth digit segment of the package version. First three segments are taken from the
+ <versionNumber> element. Must be an integer from 0 to 2^16-1 -->
+ <buildId>1</buildId>
+
+ <!-- A string value (such as "v1", "2.5", or "Alpha 1") that represents the version of the application, as it should be shown to users. Optional. -->
+ <!-- <versionLabel></versionLabel> -->
+
+ <!-- Description, displayed in the BlackBerry 10 application installer.
+ May have multiple values for each language. See samples or xsd schema file. Optional. -->
+ <description>The PropertyExample application</description>
+
+ <!-- Copyright information. Optional. -->
+ <!-- <copyright></copyright> -->
+
+ <!-- Name of author which is used for signing. Must match the developer name of your development certificate. -->
+ <author>Example Inc.</author>
+ <configuration name="Device-Debug">
+ <platformArchitecture>armle-v7</platformArchitecture>
+ <asset path="arm/o.le-v7-g/PropertyExample" entry="true" type="Qnx/Elf">PropertyExample</asset>
+ </configuration>
+ <configuration name="Device-Release">
+ <entryPointType>Qnx/Cascades</entryPointType>
+ <platformArchitecture>armle-v7</platformArchitecture>
+ <asset path="arm/o.le-v7/PropertyExample.so" entry="true" type="Qnx/Elf">PropertyExample.so</asset>
+ </configuration>
+ <configuration name="Device-Profile">
+ <platformArchitecture>armle-v7</platformArchitecture>
+ <asset path="arm-p/o.le-v7-g/PropertyExample" entry="true" type="Qnx/Elf">PropertyExample</asset>
+ </configuration>
+ <configuration name="Simulator-Debug">
+ <platformArchitecture>x86</platformArchitecture>
+ <asset path="x86/o-g/PropertyExample" entry="true" type="Qnx/Elf">PropertyExample</asset>
+ </configuration>
+
+ <!-- Unique author ID assigned by signing authority. Required if using debug tokens. -->
+ <!-- <authorId>ABC1234YjsnUk235h</authorId> -->
+
+ <initialWindow>
+ <autoOrients>true</autoOrients>
+ <systemChrome>none</systemChrome>
+ <transparent>false</transparent>
+ </initialWindow>
+
+ <!-- The icon for the application, which should be 114x114. -->
+ <icon>
+ <image>icon.png</image>
+ </icon>
+
+ <asset path="icon.png">icon.png</asset>
+ <asset path="assets">assets</asset>
+
+ <!-- Locale support -->
+ <asset path="translations" dest="qm">
+ <include name="*.qm"/>
+ </asset>
+
+ <!-- Request permission to execute native code. Required for native applications. -->
+ <permission system="true">run_native</permission>
+ <env var="LD_LIBRARY_PATH" value="app/native/lib:/usr/lib/qt4/lib"/>
+
+</qnx>
52 PropertyExample/config.pri
View
@@ -0,0 +1,52 @@
+# Auto-generated by IDE. Any changes made by user will be lost!
+BASEDIR = $$quote($$_PRO_FILE_PWD_)
+
+device {
+ CONFIG(debug, debug|release) {
+ SOURCES += $$quote($$BASEDIR/src/applicationui.cpp) \
+ $$quote($$BASEDIR/src/main.cpp)
+
+ HEADERS += $$quote($$BASEDIR/src/applicationui.hpp)
+ }
+
+ CONFIG(release, debug|release) {
+ SOURCES += $$quote($$BASEDIR/src/applicationui.cpp) \
+ $$quote($$BASEDIR/src/main.cpp)
+
+ HEADERS += $$quote($$BASEDIR/src/applicationui.hpp)
+ }
+}
+
+simulator {
+ CONFIG(debug, debug|release) {
+ SOURCES += $$quote($$BASEDIR/src/applicationui.cpp) \
+ $$quote($$BASEDIR/src/main.cpp)
+
+ HEADERS += $$quote($$BASEDIR/src/applicationui.hpp)
+ }
+}
+
+INCLUDEPATH += $$quote($$BASEDIR/src)
+
+CONFIG += precompile_header
+
+PRECOMPILED_HEADER = $$quote($$BASEDIR/precompiled.h)
+
+lupdate_inclusion {
+ SOURCES += $$quote($$BASEDIR/../src/*.c) \
+ $$quote($$BASEDIR/../src/*.c++) \
+ $$quote($$BASEDIR/../src/*.cc) \
+ $$quote($$BASEDIR/../src/*.cpp) \
+ $$quote($$BASEDIR/../src/*.cxx) \
+ $$quote($$BASEDIR/../assets/*.qml) \
+ $$quote($$BASEDIR/../assets/*.js) \
+ $$quote($$BASEDIR/../assets/*.qs)
+
+ HEADERS += $$quote($$BASEDIR/../src/*.h) \
+ $$quote($$BASEDIR/../src/*.h++) \
+ $$quote($$BASEDIR/../src/*.hh) \
+ $$quote($$BASEDIR/../src/*.hpp) \
+ $$quote($$BASEDIR/../src/*.hxx)
+}
+
+TRANSLATIONS = $$quote($${TARGET}.ts)
BIN  PropertyExample/icon.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2  PropertyExample/precompiled.h
View
@@ -0,0 +1,2 @@
+// This file is used to store precompiled headers.
+// It is intentionally left blank. It is up to you to decide which headers should be included here.
89 PropertyExample/src/applicationui.cpp
View
@@ -0,0 +1,89 @@
+/* Copyright (c) 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "applicationui.hpp"
+
+#include <bb/cascades/Application>
+#include <bb/cascades/QmlDocument>
+#include <bb/cascades/AbstractPane>
+#include <bb/cascades/LocaleHandler>
+
+using namespace bb::cascades;
+
+static AbstractPane *_root = 0;
+
+ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
+ QObject(app)
+{
+
+ _some_text = QString("Hello I am a property");
+
+ // prepare the localization
+ m_pTranslator = new QTranslator(this);
+ m_pLocaleHandler = new LocaleHandler(this);
+ if(!QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()))) {
+ // This is an abnormal situation! Something went wrong!
+ // Add own code to recover here
+ qWarning() << "Recovering from a failed connect()";
+ }
+ // initial load
+ onSystemLanguageChanged();
+
+ // Create scene document from main.qml asset, the parent is set
+ // to ensure the document gets destroyed properly at shut down.
+ QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
+
+ // Create root object for the UI
+ _root = qml->createRootObject<AbstractPane>();
+
+ // expose the property to QML
+ qml->setContextProperty("my_prop", this);
+
+ // Set created root object as the application scene
+ app->setScene(_root);
+}
+
+void ApplicationUI::onSystemLanguageChanged()
+{
+ QCoreApplication::instance()->removeTranslator(m_pTranslator);
+ // Initiate, load and install the application translation files.
+ QString locale_string = QLocale().name();
+ QString file_name = QString("PropertyExample_%1").arg(locale_string);
+ if (m_pTranslator->load(file_name, "app/native/qm")) {
+ QCoreApplication::instance()->installTranslator(m_pTranslator);
+ }
+}
+
+QString ApplicationUI::getMyProperty() {
+ logMsg("getMyProperty called");
+ return _some_text;
+}
+
+void ApplicationUI::setMyProperty(QString some_text) {
+ logMsg("setMyProperty called:" + some_text);
+ _some_text = some_text;
+ logMsg("emiting signalMyPropertyChanged");
+ emit signalMyPropertyChanged();
+}
+
+void ApplicationUI::resetMyProperty() {
+ logMsg("resetMyProperty called");
+ setMyProperty("Hello I am a property");
+}
+
+
+void ApplicationUI::logMsg(const QVariant &msg) {
+ qDebug() << "XXXX " << msg;
+ QMetaObject::invokeMethod(_root, "logMessage", Q_ARG(QVariant, msg));
+}
81 PropertyExample/src/applicationui.hpp
View
@@ -0,0 +1,81 @@
+/* Copyright (c) 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ApplicationUI_HPP_
+#define ApplicationUI_HPP_
+
+#include <QObject>
+
+namespace bb
+{
+ namespace cascades
+ {
+ class Application;
+ class LocaleHandler;
+ }
+}
+
+class QTranslator;
+
+/*!
+ * @brief Application object
+ *
+ *
+ */
+
+class ApplicationUI: public QObject
+{
+Q_OBJECT
+
+ // a Q_PROPERTY declaration is a binding between a property we can use in QML and underlying C++ methods and signals
+
+Q_PROPERTY(
+ // the name of our property as used from QML
+ QString my_property
+ // a method that will be called to populate our QML property with a value from C++
+ READ getMyProperty
+ // a method that will be called when we want to change the value of our corresponding C++ variable
+ WRITE setMyProperty
+ // a signal that will be emitted if the underlying data value changes. This signal will be automatically connected to our QML property
+ // so that anywhere our property has been used, it's value will be updated
+ NOTIFY signalMyPropertyChanged)
+
+public:
+ ApplicationUI(bb::cascades::Application *app);
+ virtual ~ApplicationUI()
+ {
+ }
+
+ // for my Q_PROPERTY
+ QString getMyProperty();
+ void setMyProperty(QString text);
+
+ Q_INVOKABLE void resetMyProperty();
+
+signals:
+ // signal that is emitted if my property value changes
+ void signalMyPropertyChanged();
+
+private slots:
+ void onSystemLanguageChanged();
+private:
+ QTranslator* m_pTranslator;
+ bb::cascades::LocaleHandler* m_pLocaleHandler;
+ // the data we bound to our QML property
+ QString _some_text;
+
+ void logMsg(const QVariant &msg);
+};
+
+#endif /* ApplicationUI_HPP_ */
35 PropertyExample/src/main.cpp
View
@@ -0,0 +1,35 @@
+/* Copyright (c) 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <bb/cascades/Application>
+
+#include <QLocale>
+#include <QTranslator>
+#include "applicationui.hpp"
+
+#include <Qt/qdeclarativedebug.h>
+
+using namespace bb::cascades;
+
+Q_DECL_EXPORT int main(int argc, char **argv)
+{
+ Application app(argc, argv);
+
+ // Create the Application UI object, this is where the main.qml file
+ // is loaded and the application scene is set.
+ new ApplicationUI(&app);
+
+ // Enter the application main event loop.
+ return Application::exec();
+}
12 PropertyExample/translations/Makefile
View
@@ -0,0 +1,12 @@
+QMAKE_TARGET = PropertyExample
+LUPDATE = $(QNX_HOST)/usr/bin/lupdate
+LRELEASE = $(QNX_HOST)/usr/bin/lrelease
+
+update: $(QMAKE_TARGET).pro FORCE
+ $(LUPDATE) $(QMAKE_TARGET).pro
+
+release: $(QMAKE_TARGET).pro $(QMAKE_TARGET).ts
+ $(LRELEASE) $(QMAKE_TARGET).pro
+
+FORCE:
+
1  PropertyExample/translations/PropertyExample.pro
View
@@ -0,0 +1 @@
+include (../PropertyExample.pro)
43 PropertyExample/translations/PropertyExample.ts
View
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.0">
+<context>
+ <name>AboutSheet</name>
+ <message>
+ <source>About PropertyExample</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>The PropertyExample application demonstrates how to use the Q_PROPERTY macro to integrate C++ resident data with QML in as simple a context as possible</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Author:</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Martin Woolley (@mdwrim)</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>V1.0.0</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
+ <name>main</name>
+ <message>
+ <source>About</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>
+</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>PropertyExample</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+</TS>
Please sign in to comment.
Something went wrong with that request. Please try again.