PDA

View Full Version : QML ApplicationWindow: Binding loop detected for property (multiple variables)



shokarta
30th January 2019, 15:48
I am quite new in QML, but I have done first sport tracking app which seems to be working, however I am having multiple warnings on each screen of binding loop... app seems to work quite fine actually.

As soon as I run the app, I have these errors:

qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getProfile"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getProfile"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getProfile"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getSummaryWorkouts"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getProfile"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getProfile"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getSummaryWorkouts"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getProfile"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getSummaryWorkouts"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getCurrentWorkout"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getProfile"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getProfile"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getSummaryWorkouts"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getProfile"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getSummaryWorkouts"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getCurrentWorkout"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getProfile"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getSummaryWorkouts"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getCurrentWorkout"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getCurrentWorkoutInput"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getProfile"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getSummaryWorkouts"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getCurrentWorkout"
qrc:/main.qml:7:1: QML ApplicationWindow: Binding loop detected for property "getCurrentWorkoutInput"

I am very interesting to learn how to declare and use variables properly!

link to the project: GitHub Project (https://github.com/shokarta/AsteroidOS---SportApp)

If there is any tips from you guys how to improve, would be much appreciated.

Here is the relevant code:

// main.qml:

import QtQuick 2.9
import QtQuick.Controls 2.0
import QtQuick.LocalStorage 2.0
import QtPositioning 5.2
import 'DatabaseJS.js' as DatabaseJS

ApplicationWindow {
visible: true
width: 400
height: 400
title: qsTr("Sports App")


// DB Settings
property string dbId: "MyDatabase"
property string dbVersion: "1.0"
property string dbDescription: "Database application"
property int dbSize: 1000000
property var db

property var getProfile: DatabaseJS.db_getProfile()
property var getSummaryWorkouts: DatabaseJS.getSummaryWorkouts()
property var getCurrentWorkout: DatabaseJS.workout_getInfo()
property var getCurrentWorkoutInput: DatabaseJS.workout_getInfoFromWorkout(getCurrentWo rkout['id'])


StackView {
id: stackView
anchors.fill: parent

initialItem: mainScreen
}

Component {
id: mainScreen
MainScreen {}
}
}

// MainScreen.qml:

import QtQuick 2.9
import QtQuick.Controls 2.0
import QtQuick.LocalStorage 2.0
import QtPositioning 5.2
import 'DatabaseJS.js' as DatabaseJS

Item {

Rectangle {
id: mainItem
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: 175

Column {
id: column2

anchors.top: parent.top
anchors.left: column1.right
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.topMargin: 30
spacing: 2

Row {
id: rowId
Text {
font.pointSize: 16
text: '<b>ID:</b> ' + getProfile['id']
}
}
Row {
id: rowGender
Text {
font.pointSize: 16
text: '<b>Gender:</b> ' + getProfile['gender']
}
}
Row {
id: rowAge
Text {
font.pointSize: 16
text: '<b>Age:</b> ' + getProfile['age'] + ' years'
}
}
Row {
id: rowWeight
Text {
font.pointSize: 16
text: '<b>Weight:</b> ' + getProfile['weight'] + ' kg'
}
}
}
}
}

// Database.JS (just examnple of getProfile):

function db_getProfile() {
// open database connection
db = LocalStorage.openDatabaseSync(dbId, dbVersion, dbDescription, dbSize);
var myVarriable = [];

db.transaction(function(tx) {
var rs = tx.executeSql('SELECT id,gender,age,weight FROM `profile`');
var ix;
for (ix = 0; ix < rs.rows.length; ++ix) {
myVarriable = {id: rs.rows.item(ix).id, gender: rs.rows.item(ix).gender, age: rs.rows.item(ix).age, weight: rs.rows.item(ix).weight};
// myVarriable = [rs.rows.item(ix).id, rs.rows.item(ix).gender, rs.rows.item(ix).age, rs.rows.item(ix).weight];
}
});
return myVarriable;
}

Thank you