I would like to write a generic template method that calculates some things and returns a value at the end typename T
. The value is obtained from QString, so I need to convert the QString to the specified one typename T
. Unfortunately, I find only the methods toDouble()
, toInt()
....
What I need:
QString s = 3.1415;
double d = s.toType<double>();
float f = s.toType<float>();
int i = s.toType<int>();
I do not want to call toDouble()
, toInt()
... because I cannot select them at compile time.
Thanks!
Edit: I could write my own specialized template functions that do just that. So,
double myOwnConvertFunction<double>(const QString& s)
then just call s.toDouble ()
I thought Qt might already have a built-in way?