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. For pair loop and qlistwidget
Forum Updated to NodeBB v4.3 + New Features

For pair loop and qlistwidget

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 516 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.
  • naaxN Offline
    naaxN Offline
    naax
    wrote on last edited by naax
    #1

    Hello guys. I can't resolve my problem.

    I have a QListWidget with an item using QMultiMap. When I add a new item he is created successfully, but if I create one more it is not showing on.
    ss1.png
    ss2.png

    Like u see in picture 2 item is adding to QMultiMap, but my loop is not showing him. I resolved it by changing my loop into this:

        ui->dailyTasksWidget->clear();
    
    
        for(auto key: DailyTaskMap.keys())
        {
                 if(key == nametodisplay)
                  {
                      //ui->dailyTasksWidget->clear();
    
                      for(auto task : DailyTaskMap.values())
                        {
                          ui->dailyTasksWidget->addItem(task);
                        }
                  }
        }
    

    but now I have double the same items.
    ss3.png

    How I can fix it?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @naax said in For pair loop and qlistwidget:

      ui->dailyTasksWidget->clear();

      That's the line that remove everything hence my question.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      naaxN 1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        How are you managing that multi map ?
        Are you sure your for loop uses the latest version of it ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        naaxN 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          How are you managing that multi map ?
          Are you sure your for loop uses the latest version of it ?

          naaxN Offline
          naaxN Offline
          naax
          wrote on last edited by
          #3

          @SGaist

          Yes. I added one more line

           ui->dailyTasksWidget->clear();
          

          before the second loop and it works, but the problem is with deleting current items now. Sorry that I'm mixing everything, but adding items and deleting current items are creating problems with one another.

          void MainWindow::highlightChecked(QListWidgetItem *item)
          {
               if(item->checkState() == Qt::Checked)
              {
          
                    for(auto& task: DailyTaskMap.values(nametodisplay))
                    {
                            Euro+=100.5;
                            UpdateData();
          
                            nametask = ui->dailyTasksWidget->currentItem()->text();
                            DailyTaskMap.remove(nametodisplay,nametask);
          
                             delete ui->dailyTasksWidget->currentItem();
                            qDebug() << DailyTaskMap.keys();
                            qDebug() << DailyTaskMap.values();
          
                            SaveDailyTasks();
                                 }
              }
                 else
              {
          
              }
          
          

          So... I can create items successfully now, but if I want to delete one of the items, then I have a problem because all items are deleting.
          ss1.png
          ss2.png

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Why are you deleting all items ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            naaxN 1 Reply Last reply
            0
            • SGaistS SGaist

              Why are you deleting all items ?

              naaxN Offline
              naaxN Offline
              naax
              wrote on last edited by naax
              #5

              @SGaist

              I don't want to delete all items. Only this one, selected, but I have a bug in my code and I don't know where is the problem.

                                delete ui->dailyTasksWidget->currentItem(); //delete current item, but this delete all items, why?
              

              then delete the item from the map

              nametask = ui->dailyTasksWidget->currentItem()->text();
              DailyTaskMap.remove(nametodisplay,nametask); //nametodisplay this is special key for every day
              
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @naax said in For pair loop and qlistwidget:

                ui->dailyTasksWidget->clear();

                That's the line that remove everything hence my question.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                naaxN 1 Reply Last reply
                1
                • SGaistS SGaist

                  @naax said in For pair loop and qlistwidget:

                  ui->dailyTasksWidget->clear();

                  That's the line that remove everything hence my question.

                  naaxN Offline
                  naaxN Offline
                  naax
                  wrote on last edited by
                  #7

                  @SGaist

                  
                            for(auto& task: DailyTaskMap.values(nametodisplay))
                            
                  

                  this loop was a problem. I got this. Thanks a lot anyway!

                  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