Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QVariantList.append() merges list instead of nesting

When I try to nest a QVariantList inside another QVariantList, the result is the flat merge of the two lists, instead of a sub-list.

Demo code:

QVariantList container;

QVariantList nested() << "bar" << "baz";

container.append("foo");  // or container << "foo";
container.append(nested); // or container << nested; 

What I obtain (indentations are mine):

QVariant(QVariantList,
  QVariant(QString, "foo"),
  QVariant(QString, "bar"),
  QVariant(QString, "baz"),
)

What I would expect:

QVariant(QVariantList,
  QVariant(QString, "foo"),
  QVariant(QVariantList, 
    QVariant(QString, "bar"),
    QVariant(QString, "baz")
  )
)
like image 455
Victor Aurélio Avatar asked Oct 31 '25 17:10

Victor Aurélio


1 Answers

Found solution by myself.

This is due the QList's append overload:

void QList::append(const QList & value)

This is an overloaded function.

Appends the items of the value list to this list.

The solution is append item using insert method:

QVariantList l;
l.insert(l.size(), QVariant());
like image 116
Victor Aurélio Avatar answered Nov 04 '25 02:11

Victor Aurélio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!