How apply std::fill() to QList?
-
wrote on 19 Nov 2018, 15:44 last edited by Engelard
Hi, i want to fill my QList<QStandardItem> with initial objects, all of them of course the same, but since QList don't have .resize function(i read google, still can't answer why Vector have when List have'nt) i can't set size of my list so i sould able to do desired thing:
std::fill(stdList, new QStandardItem("initial val"));
Do that manually through the loop take alot of time.
-
Hi
it has
http://doc.qt.io/qt-5/qlist.html#reserveAlso you show code as
QList<QStandardItem> not as QList<QStandardItem *>
so i wonder what you try ?
It would not be a good idea to preallocate a list with
QList<QStandardItem> ( none pointers) and give them to a view using &. -
Hi, i want to fill my QList<QStandardItem> with initial objects, all of them of course the same, but since QList don't have .resize function(i read google, still can't answer why Vector have when List have'nt) i can't set size of my list so i sould able to do desired thing:
std::fill(stdList, new QStandardItem("initial val"));
Do that manually through the loop take alot of time.
wrote on 19 Nov 2018, 17:15 last edited by VRonin@Engelard said in How apply std::fill() to QList?:
all of them of course the same
Define "the same".
Exactly the same object occupying the same place in memory or distinct objects with identical properties?.Why would you need a list of
QStandardItem
?!QStandardItemModel
is already a list ofQStandardItem
, no need to duplicate it.@mrjj said in How apply std::fill() to QList?:
It would not be a good idea to preallocate a list with
QList<QStandardItem> ( none pointers) and give them to a view using &.QStandardItemModel
takes ownership of the items so I think the suggestion might lead to unexpected tragedies -
@Engelard said in How apply std::fill() to QList?:
all of them of course the same
Define "the same".
Exactly the same object occupying the same place in memory or distinct objects with identical properties?.Why would you need a list of
QStandardItem
?!QStandardItemModel
is already a list ofQStandardItem
, no need to duplicate it.@mrjj said in How apply std::fill() to QList?:
It would not be a good idea to preallocate a list with
QList<QStandardItem> ( none pointers) and give them to a view using &.QStandardItemModel
takes ownership of the items so I think the suggestion might lead to unexpected tragedieswrote on 19 Nov 2018, 17:34 last edited by Engelard@VRonin said in How apply std::fill() to QList?:
or distinct objects with identical properties?.
that one.
@VRonin said in How apply std::fill() to QList?:
Why would you need a list of QStandardItem?! QStandardItemModel is already a list of QStandardItem, no need to duplicate it.
I should fill that model with the data first, then this data(list of QStandardItems) add to my model?
@mrjj tnx for reserve function.
Seems qFill took it like that
values.reserve(predefinedSize);
qFill(values, new QStandardItem("string"));But any suggestion for doing such stuff better? I don't feel confident about all this..
-
Hi
@VRonin- so I think the suggestion might lead to unexpected tragedies
You seems to have missed the "not good idea part" ? :)
or i misread your line?
But yes, you are right, should have written "hidden disaster to happen."
@Engelard
As VRonin says, the model is already such list so not sure why you want another
QList with items ? - so I think the suggestion might lead to unexpected tragedies
-
Hi
@VRonin- so I think the suggestion might lead to unexpected tragedies
You seems to have missed the "not good idea part" ? :)
or i misread your line?
But yes, you are right, should have written "hidden disaster to happen."
@Engelard
As VRonin says, the model is already such list so not sure why you want another
QList with items ?wrote on 19 Nov 2018, 18:57 last edited by Engelard@mrjj said in How apply std::fill() to QList?:
As VRonin says, the model is already such list so not sure why you want another
QList with items ?Well, starting with stringListModel where you should fill it with a data - QStringList.
So i assumed that for QStandardItemModel you should fill it with data - QStandardItem.QStandardItemModel->appendColumn() takes only QList<QStandardItem> nothing else, so i don't understand why you are even asking me about why am i trying to make QList<QStandardItem> :)
- so I think the suggestion might lead to unexpected tragedies
-
@mrjj said in How apply std::fill() to QList?:
As VRonin says, the model is already such list so not sure why you want another
QList with items ?Well, starting with stringListModel where you should fill it with a data - QStringList.
So i assumed that for QStandardItemModel you should fill it with data - QStandardItem.QStandardItemModel->appendColumn() takes only QList<QStandardItem> nothing else, so i don't understand why you are even asking me about why am i trying to make QList<QStandardItem> :)
Hi
I think the non pointer version fooled me :)
Now it all make sense.
However, normally i use
appendRow(const QList<QStandardItem *> &items)
to insert a row of data.
like```
QList<QStandardItem *> items;items.append(new QStandardItem("Column 1 Text"));
items.append(new QStandardItem("Column 2 Text"));QStandardItemModel* model = new QStandardItemModel(this);
model->setColumnCount(2);
model->appendRow(items);but appendColumn is fine too of cause depending on your data layout. Those 100.000 rows. how many columns do they have ?
-
Hi
I think the non pointer version fooled me :)
Now it all make sense.
However, normally i use
appendRow(const QList<QStandardItem *> &items)
to insert a row of data.
like```
QList<QStandardItem *> items;items.append(new QStandardItem("Column 1 Text"));
items.append(new QStandardItem("Column 2 Text"));QStandardItemModel* model = new QStandardItemModel(this);
model->setColumnCount(2);
model->appendRow(items);but appendColumn is fine too of cause depending on your data layout. Those 100.000 rows. how many columns do they have ?
wrote on 19 Nov 2018, 20:05 last edited by@mrjj said in How apply std::fill() to QList?:
Those 100.000 rows. how many columns do they have ?
Only two, only column approach is reasonable, since first column will append only once and will become unchangeable till the very end. And second column initially should be with the same value.
-
@Engelard said in How apply std::fill() to QList?:
Those 100.000 rows. how many columns do they have ?
This definitely shows that choosing a QStandardItemModel here was the wrong idea.
-
@Engelard said in How apply std::fill() to QList?:
Those 100.000 rows. how many columns do they have ?
This definitely shows that choosing a QStandardItemModel here was the wrong idea.
wrote on 19 Nov 2018, 20:13 last edited by@Christian-Ehrlicher There is no other options for QTableView, it tooks only that kind of types.
-
Sure there is: QAbstractTableModel
-
Hi
This sample might be of interest.
http://doc.qt.io/qt-5/qtwidgets-itemviews-addressbook-example.html
It both uses QAbstractTableModel and a QSortFilterProxyModel to filter it.
1/12