How to remove element after replace ?
-
wrote on 30 Aug 2021, 12:11 last edited by n-2204
Hi,
I have a Qlist with 3 stringlists, all three stringlist is in different function and appendind data in Qstring list , then adding in listQList<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. -
wrote on 31 Aug 2021, 12:09 last edited by
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);
} -
wrote on 30 Aug 2021, 14:01 last edited by
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.
-
Hi,
I have a Qlist with 3 stringlists, all three stringlist is in different function and appendind data in Qstring list , then adding in listQList<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.wrote on 30 Aug 2021, 14:13 last edited by KroMignon@n-2204 Your code seems very bad to me.
What do you expect when doingpstrList.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-2204 Your code seems very bad to me.
What do you expect when doingpstrList.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?
wrote on 31 Aug 2021, 04:40 last edited by@KroMignon
I am comparing to check ,, i don't add same element .. -
wrote on 31 Aug 2021, 04:53 last edited by n-2204
@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?? -
@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??wrote on 31 Aug 2021, 06:24 last edited by@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 aQList<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 theQStringList
will not affect ptrList.
And the same way, changing ptrList will not affect lst_m, lst_ratio orlst_cd. - You have 3
-
@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 aQList<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 theQStringList
will not affect ptrList.
And the same way, changing ptrList will not affect lst_m, lst_ratio orlst_cd.wrote on 31 Aug 2021, 06:31 last edited by@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") - You have 3
-
@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")wrote on 31 Aug 2021, 06:34 last edited by@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 caseAgain, 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.
-
wrote on 31 Aug 2021, 12:09 last edited by
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/9