title: Convert any Unicode string to int
body: <p>I have an arbitrary Unicode string that represents a number, such as "2", "٢" (U+0662, ARABIC-INDIC DIGIT TWO) or "Ⅱ" (U+2161, ROMAN NUMERAL TWO). I want to convert that string into an int. I don't care about specific locales (the input might not be in the current locale); if it's a valid number then it should get converted.</p>
  
  <p>I tried <code>QString.toInt</code> and <code>QLocale.toInt</code>, but they don't seem to get the job done. Example:</p>
  
  <pre><code>bool ok;
  int n;
  QString s = QChar(0x0662); // ARABIC-INDIC DIGIT TWO
  
  n = s.toInt(&amp;ok); // n == 0; ok == false
  
  QLocale anyLocale(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
  n = anyLocale.toInt(s, &amp;ok); // n == 0; ok == false
  
  QLocale cLocale = QLocale::C;
  n = cLocale.toInt(s, &amp;ok); // n == 0; ok == false
  
  QLocale arabicLocale = QLocale::Arabic; // Specific locale. I don't want that.
  n = arabicLocale.toInt(s, &amp;ok); // n == 2; ok == true
  </code></pre>
  
  <p>Is there a function I am missing?</p>
  
  <p>I could try all locales:</p>
  
  <pre><code>QList&lt;QLocale&gt; allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
  for(int i = 0; i &lt; allLocales.size(); i++)
  {
      n = allLocales[i].toInt(s, &amp;ok);
      if(ok)
          break;
  }
  </code></pre>
  
  <p>But that feels slightly hackish. Also, it does not work for all strings (e.g. Roman numerals, but that's an acceptable limitation). Are there any pitfalls when doing it that way, such as conflicting rules in different locales (cf. Turkish vs. non-Turkish letter case rules)?</p>