Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Using variables in SQLite queries
QtWS25 Last Chance

Using variables in SQLite queries

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
sqlite
1 Posts 1 Posters 566 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gabor53
    wrote on 16 Sept 2018, 20:58 last edited by
    #1

    Hi,
    I have a qml file (MyComboBox.qml) which includes the ComboBox I want to reuse.
    MyComboBox.qml:

    import QtQuick 2.0
    import QtQuick.Controls 2.1
    
    Item {
        Rectangle {
            id: test
            width: 400
            height: 240
            color: "#d9d9ec"
            border.color: "blue"
            border.width: 2
            anchors.top: parent.top
            anchors.topMargin: 200
            anchors.centerIn: parent.Center
    
            ComboBox {
    
                //            model: ["doll", "duck", "owl"]
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.bottom
                anchors.topMargin: 30
                font.pixelSize: 22
                editable: true
                textRole: "what"
                height: 50
                width: 230
                background: Rectangle {
                    color: "lightgreen"
                    border.width: 2
                    border.color: "darkgreen"
                    radius: 25
                }
            }
    
            Component.onCompleted: {
    
                var db = JS.dbGetHandle()
                db.transaction(function (tx) {
                    var results = tx.executeSql(
                                'SELECT "field" FROM "table" order by "field" desc')
                    for (var i = 0; i < results.rows.length; i++) {
                        listModel.append({
                                             what: results.rows.item(i).what,
                                             checked: ""
                                         })
                    }
                })
            }
        }
    }
    ``
    My main.qml, in which I want to use the ComboBox defined in MyComboBox, has the following code:
    

    import QtQuick 2.9
    import QtQuick 2.2
    import QtQuick 2.0
    import VPlayApps 1.0
    import QtQuick.Controls.Styles 1.4

    import QtQuick.Dialogs 1.3
    import QtQuick.Controls 1.1
    import QtQuick.Controls 1.4
    import QtQuick.Controls 2.2
    import QtQuick.Layouts 1.3
    import QtQuick.LocalStorage 2.0
    import QtQml.Models 2.3
    import "Database.js" as JS

    App {
    MyComboBox {
    var field = what
    var table = dropboxWhatIs

        id: whatCombo
    }
    

    }
    ``

    The Database.js has the following:

    function dbUpdate2(table, field, newText) {
        var db = dbGetHandle()
        db.transaction(function (tx) {
            tx.executeSql('UPDATE "table" "field" = ?', ['newText'])
        })
    }
    ``
    My idea was to create one combobox and reuse it for displaying choices from several tables. To do that I have to define variables field, table and newTect in the main.qml. 
    This code generates the JaaScript declaration is outside the Script element error for main.qml. Which is the best way to do what I am trying to do?
    Thank you for your help.
    1 Reply Last reply
    0

    1/1

    16 Sept 2018, 20:58

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved