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. How to remove element after replace ?
Forum Updated to NodeBB v4.3 + New Features

How to remove element after replace ?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 577 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.
  • N Offline
    N Offline
    n-2204
    wrote on 30 Aug 2021, 12:11 last edited by n-2204
    #1

    Hi,
    I have a Qlist with 3 stringlists, all three stringlist is in different function and appendind data in Qstring list , then adding in list

    QList<QStringList> pstrList;
    QStringList lst_m,lst_ratio,lst_cd;

     ////-----------function1---Qstringlist1
       lst_m.clear();
    for (int irowTable2 = 0, maxI = abstrctitem_table2->rowCount(); irowTable2 < maxI; ++irowTable2) {
        QString m = abstrctitem_table2->data(abstrctitem_table2->index(irowTable2, 0)).toString();  
         lst_m.append(m);//a b c d                    
            lst_m.removeAll("");
            if (!pstrList.contains(lst_m)) {
                pstrList.insert(0, lst_m);
            }
        }
    
    //--------------function2 ------Qstringlist2
      lst_cd.append(QString::number(CD));
           // pstrList.insert(2,lst_cd);
            if (!pstrList.contains(lst_cd)) {
                pstrList.insert(2, lst_cd);
            }
    
    //-------function 3--------Qstringlist3
     lst_ratio.append(QString::number(ratio));
                           // pstrList.insert(1,lst_ratio);
                            if (!pstrList.contains(lst_ratio)) {
                                pstrList.insert(1, lst_ratio);
                            }
    

    So in first case when I add data data it will come and add correct in Qlist and Qstring list
    but when I change something in QString m (A,B,C,D->A,B,C,E) then it will add new data but previous data will not delete how to remove the prev data , if i clear pstrList then it will clearall the data means other string list data also.

    Test case:
    QList<QStringList> *strlst= &pstrList;
    Qstringlist str is strlst->at(0), Qstringlist str2 is strlst->at(1) & Qstringlist str3 is strlst->at(2)
    1case::
    str size at 0 ("A", "B", "C", "D") size 12
    str 2 size ("1", "1", "1", "1")
    str 3 size ("3.40614", "2.43778", "2.90624", "3.4064")
    2case:when added e
    str size at 0 ("A", "B", "C", "D", "e") size 13
    str 2 size ("A", "B", "C", "D")
    str 3 size ("1", "1", "1", "1")
    3case:: when replace e with E
    str size at 0 ("A", "B", "C", "D", "E") size 14
    str 2 size ("A", "B", "C", "D", "e")
    str 3 size ("A", "B", "C", "D")
    case 1 is correct other cases are not giving correct result
    Thank you in advance.

    K 1 Reply Last reply 30 Aug 2021, 14:13
    0
    • N Offline
      N Offline
      n-2204
      wrote on 31 Aug 2021, 12:09 last edited by
      #9

      I solved it,, thank you all.
      lst_m.append(m)
      if (pstrList.size() == 0) {
      pstrList.insert(0, lst_m);
      }
      else if (!pstrList.contains(lst_m) ) {
      pstrList.replace(0, lst_m);
      }

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mchinand
        wrote on 30 Aug 2021, 14:01 last edited by
        #2

        What do you want to have happen to your stringlists when you add a value? Are your test cases what you want to happen? How are the 2nd and 3rd stringlists initially populated? Please include a complete calling sequence of your functions and please include the full functions with their declarations; you only included the function bodies (or only part of the function bodies) and don't specify how they are called.

        1 Reply Last reply
        0
        • N n-2204
          30 Aug 2021, 12:11

          Hi,
          I have a Qlist with 3 stringlists, all three stringlist is in different function and appendind data in Qstring list , then adding in list

          QList<QStringList> pstrList;
          QStringList lst_m,lst_ratio,lst_cd;

           ////-----------function1---Qstringlist1
             lst_m.clear();
          for (int irowTable2 = 0, maxI = abstrctitem_table2->rowCount(); irowTable2 < maxI; ++irowTable2) {
              QString m = abstrctitem_table2->data(abstrctitem_table2->index(irowTable2, 0)).toString();  
               lst_m.append(m);//a b c d                    
                  lst_m.removeAll("");
                  if (!pstrList.contains(lst_m)) {
                      pstrList.insert(0, lst_m);
                  }
              }
          
          //--------------function2 ------Qstringlist2
            lst_cd.append(QString::number(CD));
                 // pstrList.insert(2,lst_cd);
                  if (!pstrList.contains(lst_cd)) {
                      pstrList.insert(2, lst_cd);
                  }
          
          //-------function 3--------Qstringlist3
           lst_ratio.append(QString::number(ratio));
                                 // pstrList.insert(1,lst_ratio);
                                  if (!pstrList.contains(lst_ratio)) {
                                      pstrList.insert(1, lst_ratio);
                                  }
          

          So in first case when I add data data it will come and add correct in Qlist and Qstring list
          but when I change something in QString m (A,B,C,D->A,B,C,E) then it will add new data but previous data will not delete how to remove the prev data , if i clear pstrList then it will clearall the data means other string list data also.

          Test case:
          QList<QStringList> *strlst= &pstrList;
          Qstringlist str is strlst->at(0), Qstringlist str2 is strlst->at(1) & Qstringlist str3 is strlst->at(2)
          1case::
          str size at 0 ("A", "B", "C", "D") size 12
          str 2 size ("1", "1", "1", "1")
          str 3 size ("3.40614", "2.43778", "2.90624", "3.4064")
          2case:when added e
          str size at 0 ("A", "B", "C", "D", "e") size 13
          str 2 size ("A", "B", "C", "D")
          str 3 size ("1", "1", "1", "1")
          3case:: when replace e with E
          str size at 0 ("A", "B", "C", "D", "E") size 14
          str 2 size ("A", "B", "C", "D", "e")
          str 3 size ("A", "B", "C", "D")
          case 1 is correct other cases are not giving correct result
          Thank you in advance.

          K Offline
          K Offline
          KroMignon
          wrote on 30 Aug 2021, 14:13 last edited by KroMignon
          #3

          @n-2204 Your code seems very bad to me.
          What do you expect when doing pstrList.contains(lst_ratio)?
          This will compare each QStringList contained by pstrList and check if there is one which contains the sames strings as mst_ratio and in the same order (cf. documentation).

          Is this really what you want to do?

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          N 1 Reply Last reply 31 Aug 2021, 04:40
          0
          • K KroMignon
            30 Aug 2021, 14:13

            @n-2204 Your code seems very bad to me.
            What do you expect when doing pstrList.contains(lst_ratio)?
            This will compare each QStringList contained by pstrList and check if there is one which contains the sames strings as mst_ratio and in the same order (cf. documentation).

            Is this really what you want to do?

            N Offline
            N Offline
            n-2204
            wrote on 31 Aug 2021, 04:40 last edited by
            #4

            @KroMignon
            I am comparing to check ,, i don't add same element ..

            1 Reply Last reply
            0
            • N Offline
              N Offline
              n-2204
              wrote on 31 Aug 2021, 04:53 last edited by n-2204
              #5

              @mchinand @KroMignon
              What I'm doing is from table i am storing data in 3 QStringList lst_m,lst_ratio,lst_cd;
              then these QStringList in a QList<QStringList> pstrList;

              so in QStringList lst_m,lst_ratio,lst_cd i have correct data
              if i chnge anything in table so m clearing QStringList everytime and storing in Qstringlist
              but m not clearing my QList<QStringList> pstrList because it will have other Qstringlist data also
              so how should i remove the data from pstrList which is not in Qstringlist??

              K 1 Reply Last reply 31 Aug 2021, 06:24
              0
              • N n-2204
                31 Aug 2021, 04:53

                @mchinand @KroMignon
                What I'm doing is from table i am storing data in 3 QStringList lst_m,lst_ratio,lst_cd;
                then these QStringList in a QList<QStringList> pstrList;

                so in QStringList lst_m,lst_ratio,lst_cd i have correct data
                if i chnge anything in table so m clearing QStringList everytime and storing in Qstringlist
                but m not clearing my QList<QStringList> pstrList because it will have other Qstringlist data also
                so how should i remove the data from pstrList which is not in Qstringlist??

                K Offline
                K Offline
                KroMignon
                wrote on 31 Aug 2021, 06:24 last edited by
                #6

                @n-2204 said in How to remove element after replace ?:

                What I'm doing is from table i am storing data in 3 QStringList lst_m,lst_ratio,lst_cd;
                then these QStringList in a QList<QStringList> pstrList;
                so in QStringList lst_m,lst_ratio,lst_cd i have correct data
                if i chnge anything in table so m clearing QStringList everytime and storing in Qstringlist
                but m not clearing my QList<QStringList> pstrList because it will have other Qstringlist data also
                so how should i remove the data from pstrList which is not in Qstringlist??

                This is really confusing to me, so what I understand is:

                • You have 3 QStringList: lst_m, lst_ratio and lst_cd
                • you setup those QStringList and then copy then to a QList<QStringList> called ptrList.

                But after that, I don't understand what you want to do?!?

                Note that it is a deep copy of each QStringList into ptrList. So changing and of the QStringList will not affect ptrList.
                And the same way, changing ptrList will not affect lst_m, lst_ratio orlst_cd.

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                N 1 Reply Last reply 31 Aug 2021, 06:31
                0
                • K KroMignon
                  31 Aug 2021, 06:24

                  @n-2204 said in How to remove element after replace ?:

                  What I'm doing is from table i am storing data in 3 QStringList lst_m,lst_ratio,lst_cd;
                  then these QStringList in a QList<QStringList> pstrList;
                  so in QStringList lst_m,lst_ratio,lst_cd i have correct data
                  if i chnge anything in table so m clearing QStringList everytime and storing in Qstringlist
                  but m not clearing my QList<QStringList> pstrList because it will have other Qstringlist data also
                  so how should i remove the data from pstrList which is not in Qstringlist??

                  This is really confusing to me, so what I understand is:

                  • You have 3 QStringList: lst_m, lst_ratio and lst_cd
                  • you setup those QStringList and then copy then to a QList<QStringList> called ptrList.

                  But after that, I don't understand what you want to do?!?

                  Note that it is a deep copy of each QStringList into ptrList. So changing and of the QStringList will not affect ptrList.
                  And the same way, changing ptrList will not affect lst_m, lst_ratio orlst_cd.

                  N Offline
                  N Offline
                  n-2204
                  wrote on 31 Aug 2021, 06:31 last edited by
                  #7

                  @KroMignon as i am always copying to ptrList so if chnge in Qstringlist will effect it right.

                  prblm is when i remove anything from Qstinglist it should remove from ptrlist also its size should decrease this is not happening.
                  as i also mentioned in my test case
                  1case: correct
                  str size at 0 ("A", "B", "C", "D") size 12
                  str 2 size ("1", "1", "1", "1")
                  str 3 size ("3.40614", "2.43778", "2.90624", "3.4064")
                  2case:when added new e -correct
                  str size at 0 ("A", "B", "C", "D", "e") size 13
                  str 2 size ("A", "B", "C", "D")
                  str 3 size ("1", "1", "1", "1")
                  3case:: when replace e with E-incorrect result when i replace any thing old data is not deleted
                  str size at 0 ("A", "B", "C", "D", "E") size 14
                  str 2 size ("A", "B", "C", "D", "e")
                  str 3 size ("A", "B", "C", "D")

                  K 1 Reply Last reply 31 Aug 2021, 06:34
                  0
                  • N n-2204
                    31 Aug 2021, 06:31

                    @KroMignon as i am always copying to ptrList so if chnge in Qstringlist will effect it right.

                    prblm is when i remove anything from Qstinglist it should remove from ptrlist also its size should decrease this is not happening.
                    as i also mentioned in my test case
                    1case: correct
                    str size at 0 ("A", "B", "C", "D") size 12
                    str 2 size ("1", "1", "1", "1")
                    str 3 size ("3.40614", "2.43778", "2.90624", "3.4064")
                    2case:when added new e -correct
                    str size at 0 ("A", "B", "C", "D", "e") size 13
                    str 2 size ("A", "B", "C", "D")
                    str 3 size ("1", "1", "1", "1")
                    3case:: when replace e with E-incorrect result when i replace any thing old data is not deleted
                    str size at 0 ("A", "B", "C", "D", "E") size 14
                    str 2 size ("A", "B", "C", "D", "e")
                    str 3 size ("A", "B", "C", "D")

                    K Offline
                    K Offline
                    KroMignon
                    wrote on 31 Aug 2021, 06:34 last edited by
                    #8

                    @n-2204 said in How to remove element after replace ?:

                    prblm is when i remove anything from Qstinglist it should remove from ptrlist also its size should decrease this is not happening.
                    as i also mentioned in my test case

                    Again, I don't understand what you are writing. I am not an English native speaker, so please write clearly what your problem is. In other case I cannot help, sorry.

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    1 Reply Last reply
                    1
                    • N Offline
                      N Offline
                      n-2204
                      wrote on 31 Aug 2021, 12:09 last edited by
                      #9

                      I solved it,, thank you all.
                      lst_m.append(m)
                      if (pstrList.size() == 0) {
                      pstrList.insert(0, lst_m);
                      }
                      else if (!pstrList.contains(lst_m) ) {
                      pstrList.replace(0, lst_m);
                      }

                      1 Reply Last reply
                      0

                      5/9

                      31 Aug 2021, 04:53

                      • Login

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