[Solved]Appending to Last added QString in QStringList
-
wrote on 3 Mar 2020, 13:07 last edited by Rututraj 3 Apr 2020, 11:28
Hello All,
As my previous post this might also be a silly question, but I am processing a data and creating QStringList as its output,
but at certain point I want to append to same index of QStringList multiple times.
PseudoCode:QStringList mylist;
for(i = 0; i < 35; i++)
{
mylist.append("this is ");
if(condition)
{
mylist.append("the output");
}
}So I want "This is the output" as single string appended to same location in QStringList.
Is this possible?Thanks!
-
Hello All,
As my previous post this might also be a silly question, but I am processing a data and creating QStringList as its output,
but at certain point I want to append to same index of QStringList multiple times.
PseudoCode:QStringList mylist;
for(i = 0; i < 35; i++)
{
mylist.append("this is ");
if(condition)
{
mylist.append("the output");
}
}So I want "This is the output" as single string appended to same location in QStringList.
Is this possible?Thanks!
wrote on 3 Mar 2020, 13:30 last edited by@Rututraj said in Appending to Last added QString in QStringList:
So I want "This is the output" as single string appended to same location in QStringList.
Is this possible?
Thanks!Why not just use
QStringList::last()
?QStringList mylist; for(i = 0; i < 35; i++) { mylist.append(QString("this is")); if(condition) mylist.last().append(" the output"); }
-
Hello All,
As my previous post this might also be a silly question, but I am processing a data and creating QStringList as its output,
but at certain point I want to append to same index of QStringList multiple times.
PseudoCode:QStringList mylist;
for(i = 0; i < 35; i++)
{
mylist.append("this is ");
if(condition)
{
mylist.append("the output");
}
}So I want "This is the output" as single string appended to same location in QStringList.
Is this possible?Thanks!
the obvious solution would be to check the condition before inserting (as it's inside your loop)
QStringList mylist; for(i = 0; i < 35; i++) { QString str("this is"); if(condition) mylist.append(str); else mylist.append(str + QString("the output")); }
alternatively:
QStringList mylist; for(i = 0; i < 35; i++) { mylist.append(QString("this is")); if(condition) mylist[mylist.size()-1] = mylist.last() + QString("the output"); }
-
Hello All,
As my previous post this might also be a silly question, but I am processing a data and creating QStringList as its output,
but at certain point I want to append to same index of QStringList multiple times.
PseudoCode:QStringList mylist;
for(i = 0; i < 35; i++)
{
mylist.append("this is ");
if(condition)
{
mylist.append("the output");
}
}So I want "This is the output" as single string appended to same location in QStringList.
Is this possible?Thanks!
wrote on 3 Mar 2020, 13:30 last edited by@Rututraj said in Appending to Last added QString in QStringList:
So I want "This is the output" as single string appended to same location in QStringList.
Is this possible?
Thanks!Why not just use
QStringList::last()
?QStringList mylist; for(i = 0; i < 35; i++) { mylist.append(QString("this is")); if(condition) mylist.last().append(" the output"); }
-
@Rututraj said in Appending to Last added QString in QStringList:
So I want "This is the output" as single string appended to same location in QStringList.
Is this possible?
Thanks!Why not just use
QStringList::last()
?QStringList mylist; for(i = 0; i < 35; i++) { mylist.append(QString("this is")); if(condition) mylist.last().append(" the output"); }
@KroMignon
I could have sworn last() is a const reference only, but apparently it also has a pure reference overload 🤷♂️ -
@KroMignon
I could have sworn last() is a const reference only, but apparently it also has a pure reference overload 🤷♂️wrote on 3 Mar 2020, 14:30 last edited by@J-Hilk Other way around: const T &QList::last() const is an overload of T &QList::last(). I was surprised as well.
-
@Rututraj said in Appending to Last added QString in QStringList:
So I want "This is the output" as single string appended to same location in QStringList.
Is this possible?
Thanks!Why not just use
QStringList::last()
?QStringList mylist; for(i = 0; i < 35; i++) { mylist.append(QString("this is")); if(condition) mylist.last().append(" the output"); }
wrote on 4 Mar 2020, 11:26 last edited by@KroMignon This works fine, Thanks :)
1/7