[Qt-qml] Orientation listener

joona.t.petrell at nokia.com joona.t.petrell at nokia.com
Tue Aug 3 08:03:11 CEST 2010


Ø  So I think I need to create a C++ class which listens for the orientation changes, declare this class in my QML and then use signals so that my QML view can act upon these changes.  Is this correct?

That is one way to achieve your goals. In the future you don't necessarily need to write C++ yourself though once Qt Mobility QML bindings are finished. The bindings will be built into a bunch of QML import plugins, which you can access directly from your QML code, provided of course that Qt Mobility is installed on your device/machine and the platform you're targeting is supported (See Platform Compatibility table at the end of page http://doc.qt.nokia.com/qtmobility-1.1-tp/index.html for more information about what platforms are supported by Qt Mobility) . For example to be able to access sensors from your QML application you would just need to write "import QtMobility.sensors 1.1" at the start of your qml file.


Ø  '/Developer/source/Nokia/QtQuick/QMLTest/QMLTest.qmlproject' (/Developer/source/Nokia/QtQuick/QMLTest/QMLTest/haptics.h).  I can see these files  (header and .cpp) in Finder in OS X but they don't show up in my projects tree.


The .qmlproject project files only support purely qml+javascript-based applications. To mix C++ and QML you need to either a.) create a C++ plugin project that your QML application loads with the import syntax I already mentioned above (see Writing QML extensions http://doc.qt.nokia.com/4.7-snapshot/qml-extending-tutorial-index.html) or b.) create a C++ application project and load the QML part of your application with QDeclarativeEngine or QDeclarativeView class (see Using QML in C++ Applications http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html). Upcoming Qt Creator 2.1 will introduce a project template called "QT QML Imported Standalone Application", which automatically generates the C++ application that loads the given QML project.

Br,

Joona

From: ext Ben Marinic [mailto:ben at combinationstudios.com]
Sent: Tuesday, August 03, 2010 2:10 AM
To: Petrell Joona.T (Nokia-MS/Brisbane)
Cc: qt-qml at trolltech.com
Subject: Re: [Qt-qml] Orientation listener

Hi Joona.  Thanks for your help.  So I think I need to create a C++ class which listens for the orientation changes, declare this class in my QML and then use signals so that my QML view can act upon these changes.  Is this correct?  I'm attempting to add a C++ class to my QML project in Qt Creator but get the following error:

Failed to add one or more files to project
'/Developer/source/Nokia/QtQuick/QMLTest/QMLTest.qmlproject' (/Developer/source/Nokia/QtQuick/QMLTest/QMLTest/haptics.h).  I can see these files  (header and .cpp) in Finder in OS X but they don't show up in my projects tree.  Sorry - I'm completely new to QML/C++/Creator!

Thanks for any help
Ben

On 2 Aug 2010, at 08:13, <joona.t.petrell at nokia.com<mailto:joona.t.petrell at nokia.com>> <joona.t.petrell at nokia.com<mailto:joona.t.petrell at nokia.com>> wrote:

Hi Ben,

QML Viewer provides a simple context property runtime.orientation for listening to orientation changes on a device. It can update to four different values: portrait, portrait inverted, landscape and landscape inverted. Currently the property is updated on N900 and Symbian S60 5.0 and newer devices. For more information, see http://doc.trolltech.com/4.7-snapshot/qmlviewer.html.

For more complex orientation handling, you are better off using Sensor APIs from Qt Mobility:
http://doc.trolltech.com/qtmobility-1.1-tp/sensors-api.html

Qt Mobility teams are working on providing QML bindings for their APIs:
http://labs.trolltech.com/blogs/2010/07/27/qt-mobility-110-technology-preview/

The QML syntax will be something like

import QtMobility.sensors 1.1

OrientationSensor {
    active: true
    onReadingChanged: {
        console.log("New orientation: " + reading.orientation);
    }
}

Cheers,

Joona

From: qt-qml-bounces at trolltech.com<mailto:qt-qml-bounces at trolltech.com> [mailto:qt-qml-bounces at trolltech.com] On Behalf Of ext Ben Marinic
Sent: Thursday, July 29, 2010 7:16 PM
To: qt-qml at trolltech.com<mailto:qt-qml at trolltech.com>
Subject: [Qt-qml] Orientation listener

Hi

I need to listen for orientation changes in my QML view.  Specifically the following:  tilt right, tilt left, point up, point down, tip forward, upwards and downwards.  I can see through some old list serv threads that the syntax has changed a little over time (binding to orientations).  What is the current method for listening and executing a function on an orientation change in QML?

Thanks
Ben

Ben Marinic
Combination Studios Ltd
e. ben at combinationstudios.com<mailto:ben at combinationstudios.com>
t. +44 (0)20 7193 2000
m. +44 (0)7813 147 159






Ben Marinic
Combination Studios Ltd
e. ben at combinationstudios.com<mailto:ben at combinationstudios.com>
t. +44 (0)20 7193 2000
m. +44 (0)7813 147 159





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100803/bdfba528/attachment.html 


More information about the Qt-qml mailing list