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. [Solved] Use QTreeWidget to build a filter tree for log file
Forum Updated to NodeBB v4.3 + New Features

[Solved] Use QTreeWidget to build a filter tree for log file

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.6k 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.
  • S Offline
    S Offline
    Shimon
    wrote on last edited by
    #1

    Hi,
    I'm really new to qt, especially to QTreeWidget. The final conceptual question is below (after the tree example)

    Suppose I have a ready huge log file, each line is comma-separated and consists of several headers and then the log msg itself.
    My purpose is to build a filter tree to filter each log line by headers.

    Here are a few log-lines for example:
    LOG_FILE , Header0001 , Header0002 , Header0003 , Header0004 , MSG1
    LOG_FILE , Header0001 , Header0002 , Header0003 , Header0014 , MSG2
    LOG_FILE , Header0001 , Header0002 , Header0003 , Header0024 , MSG3
    LOG_FILE , Header0001 , Header0002 , Header0003 , Header0034 , MSG4

    LOG_FILE , Header0001 , Header0002 , Header0013 , Header0004 , MSG5
    LOG_FILE , Header0001 , Header0002 , Header0013 , Header0014 , MSG6
    LOG_FILE , Header0001 , Header0002 , Header0013 , Header0024 , MSG7
    LOG_FILE , Header0001 , Header0002 , Header0013 , Header0034 , MSG8

    So I need to build a filter tree (checkable) like the following:
    -LOG_FILE

               -Header0001
    
                                   Header0002
    
                                                     -Header0003
    
                                                                         -Header0004
    
                                                                         -Header0014
    
                                                                         -Header0024
    
                                                                         -Header0034
    
                                                     -Header0013
    
                                                                         -Header0004
    
                                                                         -Header0014
    
                                                                         -Header0024
    
                                                                         -Header0034
    

    What I can't handle is:
    If I read line by line, each log line, I split it into QStringList, so I have all the headers in a list and the MSG as the last QString.
    I can't find a way to determine if this series of QStrings exists in the tree yet.
    If exists - no need to add anything.
    If doesn't exists - I want to find the deepest last string's QTreeWidgetItem* that is common to the new series, so that I could then attach the rest of headers from that point.

    If I could have had the access to the list of items at depth-level i - then I could check if it consists the i-th header, go up in the hierarchy and check that the ancestors are really the previous headers, run it from the last header in the list, and thus detect the last uncommon string. But I don't know if there exists such func to get the list of all items at depth-level i... and it seems also not such efficient.

    Please help :( It's part of my project before army and no idea how to handle this.
    I'm sure there must be a simple way to determine if there is a route of a series in the tree and detect the place it becomes uncommon.
    Any ideas?

    Thanks a lot.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Shimon
      wrote on last edited by
      #2

      Got it!
      Thanks to the post here:
      http://www.qtcentre.org/threads/31578-List-all-elements-of-a-QTreeWidget-from-top-to-bottom
      and a little change of it:

      void MainWindow::visitTree(QStringList &list, QTreeWidgetItem *item, int currLevel, int finalLevel)
      {
      if(currLevel == (finalLevel - 1))
      {
      for(int i = 0, cCount = item->childCount(); i < cCount; i++)
      {
      list << item->child(i)->text(0);
      }
      return;
      }
      for(int i = 0; i < item->childCount(); i++)
      {
      visitTree(list, item->child(i), currLevel+1, finalLevel);
      }
      }

      void MainWindow::getListOfItemsAtLevelN(QTreeWidget *tree, QStringList& list, int finalLevel)
      {
      for(int i=0;i<tree->topLevelItemCount();++i)
      {
      visitTree(list, tree->topLevelItem(i), 0, finalLevel);
      }
      }

      call it:
      QStringList list;
      getListOfItemsAtLevelN(tree, list, 2);
      for(int i=0; i<list.count(); i++)
      {
      ui->lw->addItem(list.at(i));
      }

      P.S: it doesn't work if you pass 0, but for that we can simply use the topItemBLABLABLAs functions.

      Thanks anyway!

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BelenMuñoz
        wrote on last edited by
        #3

        You can mark the post [SOLVED].

        Regards.

        Me casé con un enano pa jartarme de reí.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Shimon
          wrote on last edited by
          #4

          where? :/

          1 Reply Last reply
          0
          • B Offline
            B Offline
            BelenMuñoz
            wrote on last edited by
            #5

            Editing the title like this: [SOLVED] Use QTreeWidget to build a filter tree for log file.

            Me casé con un enano pa jartarme de reí.

            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