I want to create a shake function using accelerometer method to change my list view item when i am shake, but I still cannot find the solution. Anyone can help me? It is urgent...
I want to create a shake function using accelerometer method to change my list view item when i am shake, but I still cannot find the solution. Anyone can help me? It is urgent...
Download Qt SDK 1.1.3 available in the Qt page.
You have to use the Sensor API (to get the sensor reading) from Qt mobility API :
http://doc.qt.nokia.com/qtmobility-1.2/quickstart.html
http://doc.qt.nokia.com/qtmobility-1.2/qml-sensor.html
regards,
This is the part I want to use shake function. For now it only can use drag and change.
import QtQuick 1.0
import QtMultimediaKit 1.1
import QtMobility.sensors 1.1
Rectangle {
id: rectangle1
width: 360
height: 640
property int i: 0
Accelerometer {
active: true
onReadingChanged: {
if( reading.x>12|| reading.x<-12)
{
}else{
}
}
}
ListView {
id: view
anchors.fill: parent
model: itemModel
preferredHighlightBegin: 0; preferredHighlightEnd: 0
highlightRangeMode: ListView.StrictlyEnforceRange
orientation: ListView.Horizontal
snapMode: ListView.SnapOneItem; flickDeceleration: 10000
cacheBuffer: 200
}
VisualItemModel {
id: itemModel
Rectangle {
id:rec1
width: view.width; height: view.height
color: "#F4F0FF"
Text {
id: page1
text: "page1"
}
Component.onDestruction: print("destroyed 1")
}
Rectangle {
id:rec2
width: view.width; height: view.height
color: "#F67008"
Text {
id: page1
text: "page2"
}
Component.onDestruction: print("destroyed 2")
}
Rectangle {
id:rec3
width: view.width; height: view.height
color: "#034621"
Text {
id: page1
text: "page3"
}
}}
Component.onDestruction: print("destroyed 3")
}
Qt quick is used to create UI, for your Qt application, you want to change the song according to sensor reading, as I got.
Write something in between this lines.Code:onReadingChanged: { if( reading.x>12|| reading.x<-12) { }
Yes..Actually I am new in this QT, and this code I refer the code from the the internet for shake and play the song. For now, what I want is, when I shake the phone, the list view will change to next page without drag it. You got what I mean?
I go the point,,there are many articles available inn the wiki (Qt wiki) for sensor .
Are you using Qt SDK 1.1.3, so check the examples, and start learning, I would suggest don't start with Sensor example, but start learning with in built examples which are given with Qt SDK.
Basically, I start learn this Qt a month a go. Now I got a project need to completed, and only this part is not completed yet.
Now my app can shake already.. But I am not using list view any more. Now the new problem is appear....the (reading.x>12|| reading.x<-12) can use?
Change the values and then run again. see what happens.
I already change the value, but my app is still lagging on my phone when I shake too fast. When I use x>20|| x-20, the shake no action..so what is the maximum value ?
I don't know which value is suitable for your code,, trial and error, is the best option.
otherwise study this articles :
http://doc.qt.nokia.com/qtmobility-1.2/sensors-api.html
http://developer.qt.nokia.com/wiki/C...es_Sensors_API
regards,