PushBack (push_back()) elements of QStringList to vector<string>

c++, qt, vector

Solution

I would do this:

foreach( QString str, list) {
  vec.push_back(str.toStdString());
}

Problem

How can I access elements of `QStringList` in a `vector<string>` type. `push_back` doesn't work. `insert`ing too needs another `vector` type only. ``` #include <QtCore/QCoreApplication> #include <QDebug> #include <QStringList> #include <vector> #include <iostream> using namespace std; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); std::vector<string> vec; QString winter = "December, January, February"; QString spring = "March, April, May"; QString summer = "June, July, August"; QString fall = "September, October, November"; QStringList list; list << winter; list += spring; list.append(summer); list << fall; qDebug() << "The Spring months are: " << list[1] ; qDebug() << list.size(); for(int i=0;i<list.size();i++) { //vec.push_back(list[i]); } exit(0); return a.exec(); } ```

Original source

Related problems