Qt World Summit: Submit your Presentation

qtquick settings set default value

  • 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
      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!

  • 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 .

  • 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?

  • 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.