[Solved]Appending to Last added QString in QStringList
-
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!
@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!
@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 🤷♂️ -
@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 This works fine, Thanks :)