1
QString line = "";
std::vector<std::pair<int, QString> >::iterator it = recordingArray.begin();

while(it != recordingArray.end())
{
  line.append(*it);
  line.append(',');
}

The above loops out a vector. I need to convert each part of the pair to a string and then add it into "line".

How can I do this?

panthro
  • 22,779
  • 66
  • 183
  • 324

1 Answers1

1

I would use a std::stringstream, then convert that to a QString

std::stringstream ss;
std::vector<std::pair<int, QString> >::iterator it = recordingArray.begin();

for(; it != recordingArray.end(); ++it)
{
  ss << it->first << ' ' << it->second.toStdString() << ',';
}

QString line = QString::fromStdString(ss.str());

EDIT: I'm not sure QString overloads operator<<(std::ostream &out, const QString &qs), so an extra conversion to std::string seems necessary.

Nicu Stiurca
  • 8,747
  • 8
  • 40
  • 48