[Development] Feature Freeze Exception: QStringView

Kevin Kofler kevin.kofler at chello.at
Thu Feb 2 23:42:32 CET 2017


Alexander Volkov wrote:
> Currently it reads into QString as in a buffer and if you need to copy
> the buffer, then you
> have to manually make a deep copy of it:
>      QTextStream ts(...);
>      QString line;
>      line.reserve(1024);
>      QStringList found;
>      while (ts.readLineInto(&line)) {
>          ...
>          found.append(QString(line.constData(), line.size())); // deep
>          copy
>      }

This should also work:
      QTextStream ts(...);
      QString line;
      line.reserve(1024);
      QStringList found;
      while (ts.readLineInto(&line)) {
          ...
          QString copy = line;
          copy.data(); // force detach (deep copy)
          found.append(copy);
      }

        Kevin Kofler




More information about the Development mailing list