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. Settings.value() use case
Forum Updated to NodeBB v4.3 + New Features

Settings.value() use case

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 4 Posters 520 Views 2 Watching
  • 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.
  • artwawA Offline
    artwawA Offline
    artwaw
    wrote on last edited by
    #1

    Good afternoon,
    I am trying to learn more of QML and as a new year exercise I am attempting to convert (rewrite) one of my existing programs into QML frontend. It is going quite well but I think I am doing something very silly here.
    I have a functionality where user can choose for program to remember and restore last login in to program. In QtWidgets instance this was resolved using QCheckBox, QInputLine and, obviously, QSettings. While I had no problem in rewriting the UI part, restoring simple string seems to be a problem.
    The code:

    Drawer {
        id: drawer
    
        Settings {
           property alias restoreLogin: saveUser.checked
        }
    
        GroupBox {
            id: loginBox
            title: qsTr("Login credentials")
            
            ColumnLayout {
                RowLayout {
                    Label {
                        text: qsTr("User name:")
                    }
                    TextInput {
                        id: uname
                        text: saveUser.checked ? Settings.value("lastLogin","") : ""
                    }
                    CheckBox {
                        id: saveUser
                        text: qsTr("Remember login")
                    }
                }
                RowLayout {
                    Label {
                        text: qsTr("Password:")
                    }
                    TextInput {
                        id: upass
                        echoMode: TextInput.Password
                    }
                }
                Button {
                    text: qsTr("OK")
                }
            }       
        }
    }
    

    The line: text: saveUser.checked ? Settings.value("lastLogin","") : ""
    gives me the error: TypeError: Property 'value' of object [object Object] is not a function

    What do I miss?

    For more information please re-read.

    Kind Regards,
    Artur

    Kiranachari ShilpiK ODБOïO 3 Replies Last reply
    0
    • artwawA artwaw

      Good afternoon,
      I am trying to learn more of QML and as a new year exercise I am attempting to convert (rewrite) one of my existing programs into QML frontend. It is going quite well but I think I am doing something very silly here.
      I have a functionality where user can choose for program to remember and restore last login in to program. In QtWidgets instance this was resolved using QCheckBox, QInputLine and, obviously, QSettings. While I had no problem in rewriting the UI part, restoring simple string seems to be a problem.
      The code:

      Drawer {
          id: drawer
      
          Settings {
             property alias restoreLogin: saveUser.checked
          }
      
          GroupBox {
              id: loginBox
              title: qsTr("Login credentials")
              
              ColumnLayout {
                  RowLayout {
                      Label {
                          text: qsTr("User name:")
                      }
                      TextInput {
                          id: uname
                          text: saveUser.checked ? Settings.value("lastLogin","") : ""
                      }
                      CheckBox {
                          id: saveUser
                          text: qsTr("Remember login")
                      }
                  }
                  RowLayout {
                      Label {
                          text: qsTr("Password:")
                      }
                      TextInput {
                          id: upass
                          echoMode: TextInput.Password
                      }
                  }
                  Button {
                      text: qsTr("OK")
                  }
              }       
          }
      }
      

      The line: text: saveUser.checked ? Settings.value("lastLogin","") : ""
      gives me the error: TypeError: Property 'value' of object [object Object] is not a function

      What do I miss?

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #4

      @artwaw

      import QtQuick 2.12
      import QtQuick.Window 2.12
      import QtQuick.Layouts 1.12
      import QtQuick.Controls 2.12
      import Qt.labs.settings 1.0
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
          Settings {
              id:st
              property alias restoreLogin: saveUser.checked
              property alias usrName :  uname.text
          }
      
          Component.onCompleted:{
      
              if(st.restoreLogin){
                  uname.text = st.usrName
              }
              else{
                  uname.text = ""
              }
          }
      
          GroupBox {
              id: loginBox
              title: qsTr("Login credentials")
      
              ColumnLayout {
                  RowLayout {
                      Label {
                          text: qsTr("User name:")
                      }
                      TextField {
                          id: uname
                      }
      
                      CheckBox {
                          id: saveUser
                          checked: st.restoreLogin
                          text: qsTr("Remember login")
                      }
                  }
                  RowLayout {
                      Label {
                          text: qsTr("Password:")
                      }
                      TextInput {
                          id: upass
                          echoMode: TextInput.Password
                      }
                  }
                  Button {
                      text: qsTr("OK")
                  }
              }
          }
      }
      
      
      1 Reply Last reply
      2
      • artwawA artwaw

        Good afternoon,
        I am trying to learn more of QML and as a new year exercise I am attempting to convert (rewrite) one of my existing programs into QML frontend. It is going quite well but I think I am doing something very silly here.
        I have a functionality where user can choose for program to remember and restore last login in to program. In QtWidgets instance this was resolved using QCheckBox, QInputLine and, obviously, QSettings. While I had no problem in rewriting the UI part, restoring simple string seems to be a problem.
        The code:

        Drawer {
            id: drawer
        
            Settings {
               property alias restoreLogin: saveUser.checked
            }
        
            GroupBox {
                id: loginBox
                title: qsTr("Login credentials")
                
                ColumnLayout {
                    RowLayout {
                        Label {
                            text: qsTr("User name:")
                        }
                        TextInput {
                            id: uname
                            text: saveUser.checked ? Settings.value("lastLogin","") : ""
                        }
                        CheckBox {
                            id: saveUser
                            text: qsTr("Remember login")
                        }
                    }
                    RowLayout {
                        Label {
                            text: qsTr("Password:")
                        }
                        TextInput {
                            id: upass
                            echoMode: TextInput.Password
                        }
                    }
                    Button {
                        text: qsTr("OK")
                    }
                }       
            }
        }
        

        The line: text: saveUser.checked ? Settings.value("lastLogin","") : ""
        gives me the error: TypeError: Property 'value' of object [object Object] is not a function

        What do I miss?

        Kiranachari ShilpiK Offline
        Kiranachari ShilpiK Offline
        Kiranachari Shilpi
        wrote on last edited by
        #2

        @artwaw

        The line: text: saveUser.checked ? Settings.value("lastLogin","") : ""

        Property values are always starting with lower case letters ,may be for that reason only that is showing error. make changes in Settings.value to

        saveUser.checked ? settings.value("lastLogin","") : ""

        hope it will works.

        1 Reply Last reply
        0
        • rrlopezR Offline
          rrlopezR Offline
          rrlopez
          wrote on last edited by rrlopez
          #3

          Hi @artwaw, what you are doing on Settings.value is not permitted by QML. You need to set an object id to your Settings object and then access that object via id.
          i.e:
          Settings {
          id: "settingsObject"
          property alias restoreLogin: saveUser.checked
          }

          And then use settingsObject.value("lastLogin","")

          Lic-Ing. Rodrigo Lopez Gonzalez
          Embedded Software Engineer
          RidgeRun Engineering Ltd.
          www.ridgerun.com
          Email: rodrigo.lopez@ridgerun.com

          1 Reply Last reply
          0
          • artwawA artwaw

            Good afternoon,
            I am trying to learn more of QML and as a new year exercise I am attempting to convert (rewrite) one of my existing programs into QML frontend. It is going quite well but I think I am doing something very silly here.
            I have a functionality where user can choose for program to remember and restore last login in to program. In QtWidgets instance this was resolved using QCheckBox, QInputLine and, obviously, QSettings. While I had no problem in rewriting the UI part, restoring simple string seems to be a problem.
            The code:

            Drawer {
                id: drawer
            
                Settings {
                   property alias restoreLogin: saveUser.checked
                }
            
                GroupBox {
                    id: loginBox
                    title: qsTr("Login credentials")
                    
                    ColumnLayout {
                        RowLayout {
                            Label {
                                text: qsTr("User name:")
                            }
                            TextInput {
                                id: uname
                                text: saveUser.checked ? Settings.value("lastLogin","") : ""
                            }
                            CheckBox {
                                id: saveUser
                                text: qsTr("Remember login")
                            }
                        }
                        RowLayout {
                            Label {
                                text: qsTr("Password:")
                            }
                            TextInput {
                                id: upass
                                echoMode: TextInput.Password
                            }
                        }
                        Button {
                            text: qsTr("OK")
                        }
                    }       
                }
            }
            

            The line: text: saveUser.checked ? Settings.value("lastLogin","") : ""
            gives me the error: TypeError: Property 'value' of object [object Object] is not a function

            What do I miss?

            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by ODБOï
            #4

            @artwaw

            import QtQuick 2.12
            import QtQuick.Window 2.12
            import QtQuick.Layouts 1.12
            import QtQuick.Controls 2.12
            import Qt.labs.settings 1.0
            
            Window {
                visible: true
                width: 640
                height: 480
                title: qsTr("Hello World")
                Settings {
                    id:st
                    property alias restoreLogin: saveUser.checked
                    property alias usrName :  uname.text
                }
            
                Component.onCompleted:{
            
                    if(st.restoreLogin){
                        uname.text = st.usrName
                    }
                    else{
                        uname.text = ""
                    }
                }
            
                GroupBox {
                    id: loginBox
                    title: qsTr("Login credentials")
            
                    ColumnLayout {
                        RowLayout {
                            Label {
                                text: qsTr("User name:")
                            }
                            TextField {
                                id: uname
                            }
            
                            CheckBox {
                                id: saveUser
                                checked: st.restoreLogin
                                text: qsTr("Remember login")
                            }
                        }
                        RowLayout {
                            Label {
                                text: qsTr("Password:")
                            }
                            TextInput {
                                id: upass
                                echoMode: TextInput.Password
                            }
                        }
                        Button {
                            text: qsTr("OK")
                        }
                    }
                }
            }
            
            
            1 Reply Last reply
            2
            • artwawA artwaw

              Good afternoon,
              I am trying to learn more of QML and as a new year exercise I am attempting to convert (rewrite) one of my existing programs into QML frontend. It is going quite well but I think I am doing something very silly here.
              I have a functionality where user can choose for program to remember and restore last login in to program. In QtWidgets instance this was resolved using QCheckBox, QInputLine and, obviously, QSettings. While I had no problem in rewriting the UI part, restoring simple string seems to be a problem.
              The code:

              Drawer {
                  id: drawer
              
                  Settings {
                     property alias restoreLogin: saveUser.checked
                  }
              
                  GroupBox {
                      id: loginBox
                      title: qsTr("Login credentials")
                      
                      ColumnLayout {
                          RowLayout {
                              Label {
                                  text: qsTr("User name:")
                              }
                              TextInput {
                                  id: uname
                                  text: saveUser.checked ? Settings.value("lastLogin","") : ""
                              }
                              CheckBox {
                                  id: saveUser
                                  text: qsTr("Remember login")
                              }
                          }
                          RowLayout {
                              Label {
                                  text: qsTr("Password:")
                              }
                              TextInput {
                                  id: upass
                                  echoMode: TextInput.Password
                              }
                          }
                          Button {
                              text: qsTr("OK")
                          }
                      }       
                  }
              }
              

              The line: text: saveUser.checked ? Settings.value("lastLogin","") : ""
              gives me the error: TypeError: Property 'value' of object [object Object] is not a function

              What do I miss?

              Kiranachari ShilpiK Offline
              Kiranachari ShilpiK Offline
              Kiranachari Shilpi
              wrote on last edited by
              #5

              Hi @artwaw ,

              you have to use Object id name to call the function of Certain Object.

              Settings {
              id: settings
              property alias restoreLogin: saveUser.checked
              }
              The line: text: saveUser.checked ? settings.value("lastLogin","") : ""

              1 Reply Last reply
              2
              • artwawA Offline
                artwawA Offline
                artwaw
                wrote on last edited by
                #6

                Thank you all for your input, I've set id property and used that, works now.
                I knew it was something silly :)

                For more information please re-read.

                Kind Regards,
                Artur

                1 Reply Last reply
                0

                • Login

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