Skip to content
QtWS25 Call for Papers
  • 0 Votes
    14 Posts
    1k Views
    jeremy_kJ

    @ECEC said in Binding C++ objects in std::vector to QML components:

    @jeremy_k

    I'm not too sure what benefit you are suggesting QStandardItemModel would have over subclassing QAbstractListModel.

    The only advantage is less stuff to write and maintain. I count 6 lines of code above, including headers, specific to the standard item model.

  • 0 Votes
    1 Posts
    464 Views
    No one has replied
  • 0 Votes
    5 Posts
    998 Views
    B

    @b-arun-kumar said in Order of QML property's dependency evaluation:
    Response from Qt Support:

    As per this old article: https://www.kdab.com/qml-engine-internals-part-2-bindings/, static value assignments happen during creation phase and binding value assignments happen at the end of creation phase.

    That is how it should be, literals first, then functions. But it is not actually documented so in theory it could change. This is also only true for simple literal assignments. Anything even slightly hinting about complexity makes QML engine postpone them together with all those needing the evaluation. For example it happens if you wrap the value with {} like this: p2: {true}

    Case 1:

    CustomQMLComponent{}

    In this case, based on the above article, p1 & p2 values are set by the time p3 value is set.

    The order in which these "static" properties are set is undefined and also the order in which more complex expressions are done are undefined. So it is best to avoid making assumptions about the order.

    Case 2:

    CustomQMLComponent{ p1: "my_string" p2: true }

    What happens in this case?

    In a more general sense, what happens when properties of a component are set when creating an instance of the component? Are the properties initialized with default values and then overridden by the new instance's values? Or, the properties are initialized just once with the default/new values.

    Just once. Although the properties do of course have some default value before the value in QML is assigned. The initial value set in constructor of a C++ class, or in case of QML defined property, default constructed value of the type (empty string, 0, false or null in case it is QObject* type).

    And why this could be important is because something like onXXXChanged signals are handled immediately when they occur and thus it could be ran before all those "static" assignment are done. Consider for example:

    onP1Changed: if (p2) {...} else {...}

    QML engine does not know that there is some dependency to p2 on p1 value change and in case p1 gets assigned before p2, this could take unexpected path and if p2 value change is not explicitly also handled properly in this case, could lead to mismatched state.

  • 0 Votes
    4 Posts
    383 Views
    B

    @GrecKo said in Is it safe to bind to C++ subobject's property in QML?:

    But why don't you do property var qmlCompProp: database.getDbpointObject() in yout qmlComp?

    prop1 and prop2 are passed to the database.getDbpointObject(prop1, prop2) function. prop1 and prop2 are properties of qmlComp. These properties are set when an instance of qmlComp is created.

    Item { required property string prop1 property bool prop2: false property var qmlCompProp: ({}) Component.onCompleted: { qmlCompProp = database.getDbpointObject(prop1, prop2) } }

    Since the properties evaluation order is undefined, and qmlCompProp depends on both prop1 and prop2 values, I've opted to initialize qmlCompProp with an empty object and assign the actual object in Component.onCompleted.
    Is this the right/recommended way, or is there a better way to handle this?

    Thanks for the information about the warning and it's workaround.

  • 0 Votes
    4 Posts
    2k Views
    Cr0ssC

    Hi @SGaist, I took you advice and finally found out where the problem is.
    I looked into Wependency Walker and realized that I can import PySide6.QWidgets before I import wiggly, So that the dlls needed is already loaded for wiggly.
    I've been testing wiggly using one single import wiggly in IPython, not runing the main.py directly in the examples, trying to copy dlls from one place to another, and kept getting ImportErrors.
    Now I write:

    import PySide6.QtWidget import wiggly

    and it works.

    Thanks for your help!

  • 0 Votes
    1 Posts
    318 Views
    No one has replied
  • 0 Votes
    2 Posts
    2k Views
    sierdzioS

    @red.green said in How to assign property values temporarily without breaking existing binding in qml?:

    How do I make sure that the previous binding is kept intact?

    Assigning a value breaks the binding - if it was not this way QML would be horribly broken ;-)

    There are a few ways around it, though. First, most obvious one - set the new value on the binding source. So if you have:

    Text { text: someProperty }

    Assign your temporary value to someProperty. You can add some code that will manage it's temporary nature there (onPropertyChanged or better in some object that holds the value of that property).

    Another way is to set up the binding using Binding element, disable it when Cancel is pressed, then enable it again once your temporary situation changes.

  • 0 Votes
    4 Posts
    711 Views
    J

    Ok, it looks like a bug introduced since Qt 5.8. I filed a bug report:
    https://bugreports.qt.io/browse/QTBUG-74332

  • SQLQuery Like problem

    Solved General and Desktop
    3
    0 Votes
    3 Posts
    422 Views
    G

    @SGaist

    My bad ! I did not think to check the docs on that point !

    A big thanks
    Gérard

  • 0 Votes
    2 Posts
    949 Views
    T

    I just ran into this issue myself, and I have a solution. I know this is an old topic, but since this was pretty much the only thing I could find on the internet about this problem, hopefully this can help someone else.

    In order to bind to a property of the nested QtObject props from the of component A, props needs to be a type of component that is known within the scope where it's properties are being accessed.

    To fix the code above, create a new file for the props Component:

    //Props.qml import QtQml 2.0 QtObject { property color mainColor }

    Now update the A component to use the Props component:

    //A.qml import QtQuick 2.0 import QtQml 2.0 Rectangle { property Props props: Props { mainColor: "blue" } color: props.mainColor }

    A few things to note here from my testing:
    If you were to now add a new property to the instance of Props in A.qml above, and try to bind a value to that , it would fail, because in the outside scope, that new property is not a known property of the Props type.
    Similarly, if you were to declare A.props as property QtObject props: Props { ... } then binding to mainColor would fail because mainColor is not a property of QtObject, and props is being exposed as a QtObject (the base class).

    It appears that the property resolution for binding to a nested property is not able to infer additional properties added to an instance of an object, and can only be bound to known properties of the type being exposed.

  • 0 Votes
    27 Posts
    13k Views
    O

    @GrecKo said in Binding C++ properties exposed to QML to dynamically created QML objects:

    Ultimately I think that you should use imperative object creation only for temporary object needed by the UI layer, like showing a dialog for example. I have yet to see another legit usecase for it (or I don't remember it).

    I will keep this in mind!

    Hopefully this little discusion might help someone else struggling to understand the same concepts!

  • 0 Votes
    2 Posts
    2k Views
    p3c0P

    @Mark81
    The cellHeight when changes updates the cellWidth in this line:

    cellWidth: Math.min(parent.width, parent.height) == parent.width ? parent.width / 3 : cellHeight

    this cellWidth change re-evaluates the binding and updates the cellHeight in this line:

    cellHeight: Math.min(parent.width, parent.height) == parent.width ? cellWidth : parent.height / 2

    And this goes on foreever and hence the error.

    By the way, how to center the GridView content? It fills the available space from left-to right.

    How do you want it to appear ? Can you share some image ?

  • 0 Votes
    2 Posts
    1k Views
    OkynO

    I have found a workaround but I am still open with a better idea..

    I have modify this source file of qt creator "src/plugins/qmldesigner/qmldesignerextension/connectioneditor/bindingmodel.cpp"
    I added the field "Global" in "Source Item" and when Global is selected in souce item I read my js file and with a regexp I add variables in "Source Property"

  • 0 Votes
    2 Posts
    25k Views
    CharbyC

    The binding loop comes from the container item where you ask the container to be of the size of its content whereas you size its content according to the parent size.

    You can either define the container dimensions as followed :

    width: dataInputField.width height: outputText.height + dataInputField.height

    but I would feel more natural to do the other way around : define the container dimension and then compute child element dimension according to the parent.

  • 0 Votes
    11 Posts
    4k Views
    R

    @SGaist OS X 10.10 and Win 10

  • 0 Votes
    2 Posts
    6k Views
    C

    Maybe

    //main.qml: import QtQuick 2.5 Loader { id: loader source: "MyComponent.qml" onLoaded: { loader.item.property1 = "secret" loader.item.property2 = 777 } } //MyComponent.qml: import QtQuick 2.0 Rectangle { id: rect property string property1 property int property2 TextEdit { id: text_edit anchors.centerIn: parent text: property1 + property2 } }

    or

    //main.qml: import QtQuick 2.5 Item { id: main width: 200; height: 200 property string property1: "secret" property int property2: 777 Loader { id: loader source: "MyComponent.qml" onLoaded: loader.item.text = property1 + property2 } } //MyComponent.qml: import QtQuick 2.0 Rectangle { id: rect property alias text: text_edit.text TextEdit { id: text_edit anchors.centerIn: parent text: property1 + property2 } }

    or

    import QtQuick 2.0 Rectangle { id: rect TextEdit { id: text_edit anchors.centerIn: parent // rect.parent -> loader; rect.parent.parent -> Item with id 'main' text: (rect.parent.parent.property1 !== undefined) ? rect.parent.parent.property1 : "" } }
  • 0 Votes
    4 Posts
    2k Views
    P

    @chrisadams I think so, I ended up reacting to a signal (from the collection of 'machines') instead of using a timer and I don't have an issue anymore!

  • 0 Votes
    1 Posts
    678 Views
    No one has replied
  • 0 Votes
    11 Posts
    5k Views
    G

    @p3c0 I tried but that didn't work. Folks on Stack Overflow don't know either. I got no other choice :
    https://bugreports.qt.io/browse/QTBUG-47407

  • 0 Votes
    2 Posts
    1k Views
    SGaistS

    Hi,

    Do you mean get additional data using QSqlQuery ?