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. Using Loader as a TableView delegate either fails or throws a warning in 6.5.0

Using Loader as a TableView delegate either fails or throws a warning in 6.5.0

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 681 Views 1 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.
  • Ahmed Yarub Hani Al NuaimiA Offline
    Ahmed Yarub Hani Al NuaimiA Offline
    Ahmed Yarub Hani Al Nuaimi
    wrote on last edited by
    #1

    I have a delegate that looks like this:
    ```

    delegate: Loader {

                sourceComponent: {
    
                    if (model === undefined || model === null
    
                            || parent === null) {
    
                        return
    
                    }
    
                    var component_qml = "import QtQuick; Component { Rectangle { border.color: 'black';"
    
                    switch(column){
                        case 0:
                            component_qml += " Text{padding: 10; text: eks_name}";
                            break;
                            .
                            .
                            .
                    }
    
                    component_qml += "}}"
    
                    return Qt.createQmlObject(component_qml, parent)
                }
            }
    
    With 6.5.0 that throws the error:
    qt.qml.typecompiler: qrc:/...../Pages/inline:1:17: Using a Component as the root of a qmldocument is deprecated: types defined in qml documents are automatically wrapped into Components when needed.
    
    If I remove the Component I get the following error:
    qrc:/......./Pages/EksPage.qml:46:17: Unable to assign QQuickRectangle to QQmlComponent
    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sami Shalayel
      wrote on last edited by Sami Shalayel
      #2

      Hello!

      It seems you are trying to bind the "object" obtained by Qt.createQmlObject() to a QQmlComponent property: this behavior is only allowed if the created object is a Component{}.

      On the other hand, it seems that the deprecation warning makes no sense in the case of code used by Qt.createQmlObject(), I will remove it.

      In general, generating qml code at runtime is a bad idea and should be avoided. I think you might check https://doc.qt.io/qt-6/qml-qt-labs-qmlmodels-delegatechooser.html out as an alternative.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sami Shalayel
        wrote on last edited by
        #3

        It seems that Qt.createQmlObject() internally makes use of QQmlComponent, such that the deprecated case of having a QQmlComponent in a QQmlComponent really happens (at least internally).

        Another alternative might be to first create a component, and then to use the setData()-slot of the component to set the qml-source code. That would avoid creating one extra QQmlComponent and triggering the warning:

        let comp = Qt.createComponent("QtQuick", "Item");
        comp.setData(component_qml); // component_qml without the Component
        
        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