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();
}
I would do this:
foreach( QString str, list) {
vec.push_back(str.toStdString());
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments