Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Property initialization, inconsistent behaviour object and literal

Qt Property initialization, inconsistent behaviour object and literal

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.9k 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.
  • S Offline
    S Offline
    SorkBarn
    wrote on last edited by
    #1

    I am using 2 Text components and intializing the text property on both. The first one is
    initialized using qsTr("Text 1") and the other one using "Text 2". The output of this is

    Output (The text i can see on the screen):

    Text 1 changed

    Text 2

    I was expecting that either no onChanged would be called or both. Is there anyone here
    that can explain to me why this is happening?

    @
    import QtQuick 1.1

    Rectangle {
    width: 360
    height: 360

    Text {
        id: lblText1;
        text: qsTr("Text 1")
    
        onTextChanged: {
            lblText1.text = "Text 1 changed";
        }
    }
    Text{
        id: lblText2;
        text: "Text 2"
        x: 0
        y: 50
    
        onTextChanged: {
            lblText2.text = "Text 2 changed";
        }
    }
    
    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
    

    }
    @

    BR

    Mattias

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      lblText1 is binding to a function, the result of which cannot be known until the runtime starts processing proper. This happens much later, i.e. when the event loop is entered.

      lblText2 is binding to a constant expression. The QML runtime has no need to re-evaluate this at a later time since it is known to be constant.

      To make lblText2 behave like lblText1 you could bind the text property to a javascript function that just returns the string.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      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