3
I have a Qvector and I want to convert it so I can make comparisons to find out which one is bigger.
I tried to do this but it doesn’t work:
QVector<QString> vector;
std::atoi(vector.value (i).toStdString ());
3
I have a Qvector and I want to convert it so I can make comparisons to find out which one is bigger.
I tried to do this but it doesn’t work:
QVector<QString> vector;
std::atoi(vector.value (i).toStdString ());
4
You can convert a Qstring to int using Qt itself:
vector.at( i ).toInt();
Or, if you only need the amount:
QVector<QString> vector;
vector << "1278" << "7" << "9";
int max = 0;
foreach (QString s, vector) {
max = qMax( max, s.toInt() );
}
qDebug() << max;
3
Incredible as it may seem (so big that is the QT) class QString
has a method that makes the Parsing of its contents to whole, gives a look at QString.toInt
.
Thanks for your help.
Browser other questions tagged c++ qt
You are not signed in. Login or sign up in order to post.
I didn’t even think to see if there was a method in Qstring itself. Thank you very much
– Giovani
@Giovaniracipaganini @Wakim’s reply was already good, but I chose to add an example with
foreach
, which may be useful as well, depending on your practical case.– Bacco
Yes, I think it’s worth setting the example, I didn’t think of it at the time.
– Wakim