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. View a List of QLabel

View a List of QLabel

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.7k Views 2 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.
  • G Offline
    G Offline
    Ggwppino
    wrote on last edited by
    #1

    Hi! I'm new to Qt and I want to create an application that has a list of hyperlink and RichTex that is displayed in Layout ui.
    I Tried to use setItemWidget of listWidget but it create memoryLeak for every QLabel i have (rightly).

    any advice or help?

    Pl45m4P 1 Reply Last reply
    0
    • G Ggwppino

      @mrjj thanks for the reply,

      I'm already doing it this way

          void mainwindow::printHyperLink(QString in){
              QListWidgetItem *item;
              QLabel * myLabel;
              bool opened = in!="Error";
          
              if (opened)
              {
          
                  item = new QListWidgetItem("");
                  ui->listWidget1->addItem(item);
                  myLabel = new QLabel(in, this);
                  myLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
                  myLabel->setOpenExternalLinks(true);
                  ui->listWidget1->setItemWidget(item, myLabel);
              } else {
                  item = new QListWidgetItem("Error");
                  ui->listWidget1->addItem(item);
              }
          }
      

      practically this function is called every time one of my threads finishes processing a link.

      Could this create problems with valgrind?
      I specify that the problem persists even if I manually add only one item in ListWidget in mainwindow.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #8

      Hi
      Then it seems like a false positive as you set a parent so they will be cleaned up but
      if the parent live long then it will first be much later that might fool
      valgrind.

      1 Reply Last reply
      1
      • G Ggwppino

        Hi! I'm new to Qt and I want to create an application that has a list of hyperlink and RichTex that is displayed in Layout ui.
        I Tried to use setItemWidget of listWidget but it create memoryLeak for every QLabel i have (rightly).

        any advice or help?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #2

        @Ggwppino said in View a List of QLabel:

        setItemWidget of listWidget but it create memoryLeak for every QLabel i have

        If you add new items to your QListWidget, you dont have memory leaks. The parent (ListWidget takes care of all child items)


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        2
        • G Offline
          G Offline
          Ggwppino
          wrote on last edited by
          #3

          thanks for the reply, it reassures me.
          actually valgrind does not notify me of any problems in the memcheck section but When i click any QLabel with hyperlink in my application output, appear a lot of Valgrind notification of Memory leaks writed in xml.

          Pl45m4P 1 Reply Last reply
          0
          • G Ggwppino

            thanks for the reply, it reassures me.
            actually valgrind does not notify me of any problems in the memcheck section but When i click any QLabel with hyperlink in my application output, appear a lot of Valgrind notification of Memory leaks writed in xml.

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #4

            @Ggwppino

            What labels? Do you mean QListWidgetItems?


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Ggwppino
              wrote on last edited by
              #5

              i Need to show in Layout a List of hyperlink. QLabel has possibility for containing richtext, so I do:

              ui->listWidget->setWidgetItem(item, myLabel)
              

              In memcheck, valgrind doesn't warning me, but in Application Output there are a lot of Valgrind error.

              mrjjM 1 Reply Last reply
              0
              • G Ggwppino

                i Need to show in Layout a List of hyperlink. QLabel has possibility for containing richtext, so I do:

                ui->listWidget->setWidgetItem(item, myLabel)
                

                In memcheck, valgrind doesn't warning me, but in Application Output there are a lot of Valgrind error.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #6

                @Ggwppino
                The docs don't say it takes ownership so try to give the Label a parent. ( as far as i could find)
                I think it does own it but try and see if it stops the valgrind warnings.

                auto label = new QLabel( ui->listWidget);
                ui->listWidget->setItemWidget(ui->listWidget->item(0), label);
                

                Also note that valgrind might not understand Qt system in all cases.
                https://doc.qt.io/qt-5/objecttrees.html

                G 1 Reply Last reply
                1
                • mrjjM mrjj

                  @Ggwppino
                  The docs don't say it takes ownership so try to give the Label a parent. ( as far as i could find)
                  I think it does own it but try and see if it stops the valgrind warnings.

                  auto label = new QLabel( ui->listWidget);
                  ui->listWidget->setItemWidget(ui->listWidget->item(0), label);
                  

                  Also note that valgrind might not understand Qt system in all cases.
                  https://doc.qt.io/qt-5/objecttrees.html

                  G Offline
                  G Offline
                  Ggwppino
                  wrote on last edited by Ggwppino
                  #7

                  @mrjj thanks for the reply,

                  I'm already doing it this way

                      void mainwindow::printHyperLink(QString in){
                          QListWidgetItem *item;
                          QLabel * myLabel;
                          bool opened = in!="Error";
                      
                          if (opened)
                          {
                      
                              item = new QListWidgetItem("");
                              ui->listWidget1->addItem(item);
                              myLabel = new QLabel(in, this);
                              myLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
                              myLabel->setOpenExternalLinks(true);
                              ui->listWidget1->setItemWidget(item, myLabel);
                          } else {
                              item = new QListWidgetItem("Error");
                              ui->listWidget1->addItem(item);
                          }
                      }
                  

                  practically this function is called every time one of my threads finishes processing a link.

                  Could this create problems with valgrind?
                  I specify that the problem persists even if I manually add only one item in ListWidget in mainwindow.

                  mrjjM 1 Reply Last reply
                  0
                  • G Ggwppino

                    @mrjj thanks for the reply,

                    I'm already doing it this way

                        void mainwindow::printHyperLink(QString in){
                            QListWidgetItem *item;
                            QLabel * myLabel;
                            bool opened = in!="Error";
                        
                            if (opened)
                            {
                        
                                item = new QListWidgetItem("");
                                ui->listWidget1->addItem(item);
                                myLabel = new QLabel(in, this);
                                myLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
                                myLabel->setOpenExternalLinks(true);
                                ui->listWidget1->setItemWidget(item, myLabel);
                            } else {
                                item = new QListWidgetItem("Error");
                                ui->listWidget1->addItem(item);
                            }
                        }
                    

                    practically this function is called every time one of my threads finishes processing a link.

                    Could this create problems with valgrind?
                    I specify that the problem persists even if I manually add only one item in ListWidget in mainwindow.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    Hi
                    Then it seems like a false positive as you set a parent so they will be cleaned up but
                    if the parent live long then it will first be much later that might fool
                    valgrind.

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved