[Solved] Issue with delegate



  • Hi,

    I've wrote a module base on a delegate example "Accessing Views and Models from Delegates" from "here":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativemodels.html . Basically I have separate  model, view and delegate into three qml file. 
    
    And I use them into a main qml file by calling the view module. It work fine. But if I use a .bat file to launch my main qml file the delegate can't access the model. I need a .bat to open the qmlviewer with -opengl option.
    
    "Here":http://dl.free.fr/nfP6HLyJ7 you can find a archive to test by yourself, try launching main.qml and the bat file. 
    

    Thanks



  • Sounds like an issue with paths that are set if you run from the Qt Creator context, but not if you run from your .bat file.



  • I never launch from qt creator. I have assign .qml to qmlviewer. So i double click on a qml file, but here I need -opengl. Anyway for me it look like a scope mistake. But I don't know what I should do.

    Have tested my issue with the given files ?



  • Change view.qml to View.qml

    bq. Any snippet of QML code can become a component, by placing the code in a file "<Name>.qml" where <Name> is the new component name, beginning with an uppercase letter.
    from http://doc.qt.nokia.com/4.7/qml-extending-types.html



  • Thanks for your answer but I made this mistake while i was trying to reproduce the bug, sorry for that.

    In fact, i don't use a listview but a personal view like this one :
    PersonnalView.qml
    @import QtQuick 1.0

    Item {
    property alias model: rept.model
    property Component delegate:Component { Rectangle{} }

    Column {
    Repeater
    {
    id:rept
    Loader
    {
    sourceComponent: delegate;
    }
    }
    }
    }@

    Used that way in View.qml
    @import QtQuick 1.0

    PersonnalView{
    width:300
    height:300

    model:Model{}
    delegate:Delegate{}

    }@

    And again used in a main qml file I still got the same scope bug.
    I've uploaded "here":http://dl.free.fr/kr26FMm75 a new version of my code which still doesn't work if launched by a .bat but work if directly launched by main file.

    Thanks



  • I don't get a different behavior if launching by a .bat or directly. However, the example doesn't work because the Repeater's model data doesn't get automatically bound to the Loader's source component. The model data can be passed through the Loader manually with the following changes.

    Modified PersonnalView.qml
    @
    import QtQuick 1.0

    Item {
    property alias model: rept.model
    property Component delegate:Component { Rectangle{} }

    Column {
        Repeater {
            id:rept
            Loader {
                property string name: rept.model.get(index).name
                property string cost: rept.model.get(index).cost
                sourceComponent: delegate;
            }
        }
    }
    

    }
    @



  • Thanks that work great, but I still need to adapt my view to my model which doesn't seems quite well. I guess that works with ListView, GridView ... Because they aren't made of qml file but c++ plugin...

    This will let an open debate I think, Because personal view might be something user want to do.

    Thanks again for your help.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.