Search code examples
replaceqt5qstring

Change the ith element of a QStringList


I am searching solution for half hour and no progress.

Consider the list

QStringList foo = {};
for (int i=1; i<8; i++){
    foo << "0";
}

If some check box was clicked, I'd like to change the value of the list to "1".

So, for example, how to change the 3rd 0 by 1? Something like (pseudo code) foo.replace(3,"0","1").


Solution

  • Just apply the KISS principle ;)

    foo[3] = "1";