1

Unfortunately, our software uses certain data-holding object called ProcessContext which holds the data in string indexed map (QMap<QString, QVariant>. This patter will not be changed right now but I need to stuff more complex data than string and numbers to it.

My specific data is a QList<MyClass> which contains instances of my own class. Surprisingly such list really can be converted to and from QVariant. I asked question about that: Can I conveniently converty QVariant back to QList<MyType>?

The procedure looks like:

QList<MyType> list_original;
QVariant variant = QVariant::fromValue(list_original);
// And later on...
 if( variant.canConvert<QList<MyType>>() ) {
     QList<MyType> list_new = variant.value<QList<MyType>>();
     ...
 }

Now the issue here is, that any changes done to list_new will not affect the data in the QVariant variant.

My question here therefore is how to ensure that the QVariant returns refference on the data it covers, rather than copy.

Community
  • 1
  • 1
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • is it not possible to set the variant variable to the changed list? – Karsten Koop May 17 '16 at 13:54
  • It is but feels dirty. It also means care must be taken to first do all the changes and then update the value in `QVariant`. That's simple in a single function, but not if the `QList` is assigned to a class property... – Tomáš Zato May 17 '16 at 13:56
  • 3
    You can't that way. QVariant stores a copy and `value()` returns a value, so a copy. Wrap a (smart) pointer instead? – peppe May 17 '16 at 15:03

0 Answers0