Important: Please read the Qt Code of Conduct -

Custom Model in defined TreeView in Designer

  • Hello,

    I'm new on QT and i'm trying to use the SimpleTreeModel in a Designer defined TreeView.

    My TreeView is set as "cardView".

    But it isn't shown.

    QFile file(":/dateien/default.txt");; 
    cardViewModel model(file.readAll()); 

    Everyting is the same like in the example, i just changed the names of TreeView and TreeItem as following;

    TreeItem -> cardViewItem
    TreeModel -> cardViewModel

  • No it is not the same.

    Example instantiate both model and view in the main.
    This means they both exist until application (main) exits.

    It looks like you are doing it in one of the function of the class created by designer (likely constructor).
    When you create object on the stack it is deleted when it goes out of scope.
    So cardViewModel model gets deleted.

    You probably want to add cardViewModel * model member to the class, allocate it on the heap, pass the poi9nter to view and destroy in the constructor.

  • Lifetime Qt Champion

    If you make cardViewModel member of the class then there is no need to make it a pointer and allocate it on the heap.

  • Thank you now it's working.

    Now i'm getting the following

    QStringList columnStrings = lineData.split("|");
    QList<QVariant> columnData;

    how can I now check if the columnData starts with a '#' and define it as root and if not define it as child of

Log in to reply