Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Qt QtStrToInt

 

QtStrToInt is a conversion code snippet to convert a QString to an integer.

 

#include <cassert>
#include <QString>

//From http://www.richelbilderbeek.nl/CppQtStrToInt.htm
int QtStrToInt(const QString& s)
{
  bool okay = true;
  const int i = s.toInt(&okay);
  assert(okay == true);
  return i;
}

//From http://www.richelbilderbeek.nl/CppIntToQtStr.htm
QString IntToQtStr(const int i)
{
  QString s;
  s.setNum(i);
  return s;
}

int main()
{
  assert(QtStrToInt("123")==123);
  assert(IntToQtStr(123)=="123");
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict