import QtQuick 2.4
import QtQuick.LocalStorage 2.0
Rectangle {
property alias mouseArea: mouseArea
//property variant r1: Array()
property variant r1: []
property int tedad
width: 360
height: 360
MouseArea {
id: mouseArea
anchors.fill: parent
}
function fdatabase() {
var db = LocalStorage.openDatabaseSync("ravandi", "1.0", "The Example QML SQL!", 1000000);
db.transaction(
function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS jadval(id integer primary key autoincrement not null,`name` varchar(40),`last` varchar(40))');
tx.executeSql("insert into jadval (name,last) values('ahmad','ravandi')");
var rs = tx.executeSql('SELECT * FROM jadval');
tedad = rs.rows.length;
var items = [];
for(var i = 0; i < rs.rows.length; i++) {
items.push(rs.rows.item(i).name);
r1 = items;
print(r1)
// r1 +=rs.rows.item(i).name
}
}
)
}
Component.onCompleted: fdatabase()
Column {
spacing: 5;
Repeater {
model: tedad;
Rectangle {
width:100
height:30
border.color: "red"
border.width: 1
Text{
id:items
anchors.horizontalCenter: parent.horizontalCenter
renderType: Text.NativeRendering
text: r1
}
}
}
}
}
import QtQuick 2.4
import QtQuick.LocalStorage 2.0
Rectangle {
property alias mouseArea: mouseArea
//property variant r1: Array()
property variant r1: []
property int tedad
width: 360
height: 360
MouseArea {
id: mouseArea
anchors.fill: parent
}
function fdatabase() {
var db = LocalStorage.openDatabaseSync("ravandi", "1.0", "The Example QML SQL!", 1000000);
db.transaction(
function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS jadval(id integer primary key autoincrement not null,`name` varchar(40),`last` varchar(40))');
tx.executeSql("insert into jadval (name,last) values('ahmad','ravandi')");
var rs = tx.executeSql('SELECT * FROM jadval');
tedad = rs.rows.length;
var items = [];
for(var i = 0; i < rs.rows.length; i++) {
items.push(rs.rows.item(i).name);
r1 = items;
print(r1)
// r1 +=rs.rows.item(i).name
}
}
)
}
Component.onCompleted: fdatabase()
Column {
spacing: 5;
Repeater {
model: tedad;
Rectangle {
width:100
height:30
border.color: "red"
border.width: 1
Text{
id:items
anchors.horizontalCenter: parent.horizontalCenter
renderType: Text.NativeRendering
text: r1
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
erorr:
2016/01/28 21:29:04 sqlite.qml.:47: file:///F:/workspace/sqlite.qml.:47:12: Unab
le to assign QJSValue to QString
Bookmarks