Let Qt models meet std::vector<std::tuple<…>>

The problem

So. I was stuck with a container of tuples that I wanted to see in a Qt view (QTableView, QtQuick ListView or similar). So how to do that?

Another problem: I haven’t been doing fun things with templates recently.

A solution?

After a bit of hacking, it seems like it can just be done like

and … tada:
QTableView

Of course, we are also QtQuick friendly

and a delegate containing the following

 

can give:
ListView

But enough about creation.

Whattabout manipulation?

Luckily we got you covered. Insert two extra rows at position 1?

Append a row?

Remove 2 rows at position 3?

Replace the underlying list?

Read-only looping over the elements?

The Qt model of course also accepts setData calls.

Future?

If anyone is interested I will polish the code a bit and publish it. If that’s the case, how should I name this thing?

And I did get around doing fun things with templates again.

Posted in english, kde, Pocket projects, qt
One comment on “Let Qt models meet std::vector<std::tuple<…>>
  1. Erik Thon says:

    Nice one. But maybe instead of typedef I*d prefer using:
    using Element = std::tuple;