How i could convert Persian numbers to English numbers using QLocale?

174 Views Asked by At

I want to convert Persian numbers to English numbers using QLocale, i wrote this code but it fail:

int main(void)
{
    QLocale english_number(QLocale::Language::English, QLocale::Country::UnitedStates);
    QTime time;

    time = english_number.toTime("۱۲:۳۲", "HH:mm");

    qDebug() << time;
}

Console output:

QTime(Invalid)

But it's possible to convert English numbers to Persian numbers:

QLocale persian_number(QLocale::Language::Persian, QLocale::Country::Iran);

time = persian_number.toTime("13:32", "HH:mm");

qDebug() << time;

Console Output:

QTime("13:32:00.000")

Where did i go wrong ?

  • Qt: 5.14.1
  • OS: Archlinux-5.6.7-arch1-1
  • Compiler: GCC 9.3
1

There are 1 best solutions below

0
On BEST ANSWER

I think it's a Qt Bug, for doing this before converting to QTime we need to convert Persian numbers to int and then convert to QTime.