Increasing QList<QStringList> contents twice!
-
Not really sure what you are trying to do. Also the outcome seem not to match what I would expect.
Anyway checkout the doucmentation for QStringList &QStringList::operator<<(const QList<QString> &other)
QStringList list1; list1<<"a"<<"b"<<"c"<<"d"<<"e"; // list1 should contain "a" "b" "c" "d" "e" beause you copy individual strings QStringList List1; // List1 is empty // copy one QStringList to another List1 << list1; // List1 should contain "a" "b" "c" "d" "e" because you copied with operator<< as described above // repeat to add another copy List1 << list1; // List1 should contain "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" because you appended twice
-
@koahnig
List1
is of typeQList<QstringList>
(i guessed from the title)@Kushan said in increasing QList<QStringList> contents twice!:
Thanx but if I add another QStringList list2<<"f"<<"g"<<"h"<<"i"<<"j"; to List1 how can I get twice of its contents also?
List1<<list1; List1[0]<<list2; List1[0] << List1[0]; //this is the duplication
-
@JNBarchan said in increasing QList<QStringList> contents twice!:
Have you each been set homework?
My guess is the same class at University of Colombo School of Computing. I was too lazy to run a cross-correlation analysis on the posts, though, so don't take any of this at face value ... but then again ... if it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck.
-
@kshegunov
Excluding the code (which is virtually identical, including the lack of spaces), they both have:In my Qt C++ application I have a QList<QstringList> I want to increase the contents of its 0th index by the same amount!
...
from the above code I want to make the contents of 0th index of List (i.e List[0]) a QStringList of "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" ... How can I correct this?That's the same down to the "!"-mark! Something fishy is going on with ducks here... ;-)
It's interesting to hear that Qt is being used in an education course. But why Qt for this question? There's nothing special about
QList
orQStringList
, this could just as well have been posed for std C++. If you're going to teach Qt I would have expected a Qt-ish question, else don't bother. -
@kshegunov said in increasing QList<QStringList> contents twice!:
if it looks like a duck, swims like a duck, and quacks like a duck
Slight thread derail, but I would say the op's question general is answered .