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. qtquick settings set default value

qtquick settings set default value

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qtquickqt.lab.settingssettingsbinding looptextfield
4 Posts 2 Posters 1.2k 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.
  • J Offline
    J Offline
    jay mainpy
    wrote on 1 Jun 2021, 10:43 last edited by
    #1

    i'm trying to set a default value to a TextField if the application never ran on that persons system yet. I do this by using the Settings {} in the QML and assigning the alias if it was set:

    import Qt.labs.settings 1.0
    import QtQuick 2.12
    ...
    TextField{
      ...
      text: settings.extendExportFile === "" ? "_result_" : settings.extendExportFile
    }
    

    so far this seems to work well, but if i edit the textfield while the application is running and change the value of the TextField from "result" to be empty (temporarily wile typing), the textfield is instantly filled with "result" again. I can see how this happens from the short javascript function, but i'd like to know how i can avoid this behaviour, or if there is a better way to set default values. The error message i get is:

    QML TextField: Binding loop detected for property "text"
    

    And on a nother note, can i also use Settings{} in the .qml to save them to a file specified by the user with textfield and a Button?

    Thank you for your Answer in advance!

    1 Reply Last reply
    0
    • F Offline
      F Offline
      flowery
      wrote on 1 Jun 2021, 13:19 last edited by
      #2

      Are you doing something like this to trigger binding loop.
      Text {
      id: settings
      anchors.centerIn: parent
      text: field.displayText

      }
      
      TextField {
          id: field
          text: settings.text === "" ?"_result_" : settings.text
      }
      

      Binding loop will be detected if value of settings.extendExportFile is bound to TextField's text.
      If so get rid of it by assigning value to settings.extendExportFile
      To save settings in file you can C++ class .

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jay mainpy
        wrote on 2 Jun 2021, 10:37 last edited by jay mainpy 6 Feb 2021, 10:41
        #3

        no my settings looks like this with qt.labs.settings 1.0 :

        Settings {
          id: settings
          property alias extendExportFile: textfieldID.text
        }
        

        which as far as i know saves the settings to an .ini file or the windows registry...depending on the users system.

        The binding loop happens if i edit the text field while the program is running. I can edit it just fine but as soon as it is empty, the default result text is inserted again. Understandable what i mean?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          flowery
          wrote on 2 Jun 2021, 14:27 last edited by
          #4

          I just gave a example.You should read what is binding loop.It clearly says you have a binding loop.
          settings.extendExportFile is bound to textfieldId.text
          textfieldId.text is bound to settings.extendExportFile
          Whenever settings.extendExportFile changes which trigger a signal to change textfieldId.text and in turn this trigger a signal to change settings.extendExportFile.This will be happening in a loop, which is known as binding loop.

          1 Reply Last reply
          0

          4/4

          2 Jun 2021, 14:27

          • Login

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