Googie
Googie

Reputation: 6067

QString::toLongLong() cannot handle big hex numbers

Qt 5.4.1, Linux 64 bit. A sample code:

int main(int argc, char** argv)
{
    QString a = "FFFFFFFFFFFFFFFF";
    bool ok;
    qDebug() << a.toLongLong(&ok, 16);
    qDebug() << ok;
    return 0;
}

It should display:

-1
true

but displays:

0
false

It works fine for smaller numbers. Why is it so weird? Am I doing something wrong?

Upvotes: 1

Views: 508

Answers (2)

user4590913
user4590913

Reputation:

If you try a.toULongLong(&ok, 16); then the result is:

18446744073709551615

true

take a look of the limits http://en.wikipedia.org/wiki/C_data_types#limits.h

Upvotes: 0

Perfect28
Perfect28

Reputation: 11317

Actually the maximum value that can handle a long long is 2^63 - 1, as it is signed. What you've got here is 2^64 - 1. That's why it can't parse it.

May be you should try with QString::toULongLong.

Upvotes: 2

Related Questions