Qt World Summit: Submit your Presentation

One delegate for 2 model object.

  • Hello All.
    I started a project using Qt model view technology. I created model class and I have 2 object of this model class:
    Mymodel *model1 = new Mymodel;
    Mymodel *model2 = new Mymodel;

    and I have also a delegate class, but I have only one object,
    Mydelegate *delegate = new Mydelegate;

    I have 2 view object also:
    QTableView *view1 = new QTableView;
    QTableView *view2 = new QTableView;

    view1 -> setModel(model1);
    view1 -> setItemDelegate(delegate);
    view2 -> setItemDelegate(delegate);
    view2 -> setModel(model2);

    So I am interested if my 1 delegate object is enough for all, I am confused if this will work correctly when I call index -> model() in delegate, which model it will point to?
    thank you!

  • Lifetime Qt Champion

    @tokafr said:

    Mydelegate *delegate = new Mydelegate;

    hi, i might miss something but why dont you just create another instance?

    Mydelegate *delegate2= new Mydelegate;
    view2 -> setItemDelegate(delegate2);

    Normally a delegate (instance) is not shared between views as its not intended.