Convert QVectorQString to int in C ++

3

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 ());
    
asked by anonymous 01.06.2014 / 02:40

2 answers

4

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;

link

    
01.06.2014 / 02:50
3

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 .

    
01.06.2014 / 02:43