I have a QVector and I want to convert it so I can make comparisons to find out which one is greatest.
I tried to do this but it does not work:
QVector<QString> vector;
std::atoi(vector.value (i).toStdString ());
I have a QVector and I want to convert it so I can make comparisons to find out which one is greatest.
I tried to do this but it does not work:
QVector<QString> vector;
std::atoi(vector.value (i).toStdString ());
You can convert a QString to int using Qt itself:
vector.at( i ).toInt();
Or, if you only need the value:
QVector<QString> vector;
vector << "1278" << "7" << "9";
int max = 0;
foreach (QString s, vector) {
max = qMax( max, s.toInt() );
}
qDebug() << max;
As unbelievable as it sounds (the QT is so big), the QString
class has a method that parses the contents of the entire content, looks at QString.toInt
.