Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Custom Model in defined TreeView in Designer
Forum Updated to NodeBB v4.3 + New Features

Custom Model in defined TreeView in Designer

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 970 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.
  • R Offline
    R Offline
    Rocky
    wrote on last edited by
    #1

    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"); 
    file.open(QIODevice::ReadOnly); 
    cardViewModel model(file.readAll()); 
    file.close(); 
    ui->cardView->setModel(&model);
    

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

    TreeItem -> cardViewItem
    TreeModel -> cardViewModel

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

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

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rocky
          wrote on last edited by
          #4

          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

          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