How can I convert QVariant to QString and Vice versa?
Thanks
From string:
QString qs;
QVariant qv(qs);
To string:
QString qs = qv.toString();
Tip: reading the help helps.
value<QString>()
is the same as toString()
. They both use canConvert()
and convert()
internally.
Commented
Apr 3, 2016 at 9:16
toString()
appears to have begun working in qt 4.8; in qt 4.7, value<QString>()
works, while toString()
does not. So for this kind advice and compatibility, value<QString>()
makes for a better general statement, unless qualified by version.