Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert QVariant to QString and vice versa in Qt?

Tags:

c++

qt

How can I convert QVariant to QString and Vice versa?

Thanks

like image 550
Legend Avatar asked Aug 29 '11 10:08

Legend


People also ask

What is QVariant in Qt?

Because C++ forbids unions from including types that have non-default constructors or destructors, most interesting Qt classes cannot be used in unions. Without QVariant, this would be a problem for QObject::property() and for database work, etc. A QVariant object holds a single value of a single typeId() at a time.


1 Answers

From string:

QString qs; QVariant qv(qs); 

To string:

QString qs = qv.toString(); 

Tip: reading the help helps.

like image 50
hamstergene Avatar answered Sep 22 '22 17:09

hamstergene