Resizing QList for Qt5
-
Hi. I'm on Qt 5.15. I'm trying to create a QList of ints and fill them with 0s. I wanted to use resize() but it doesn't seem to be available for Qt5. Is there a workaround or do I have to manually append the list by quite a few times?
-
@jsulm reserve does not resize the list :(
@Dummie1138 You might want to use QVector instead, which has resize. In Qt6 QList and QVector are the same anyway.
If not then you'll have to add them one by one e.g. like this, but it's not very efficient for a large n:list.reserve(n); std::fill_n(std::back_inserter(list), n, 0); -
Hi. I'm on Qt 5.15. I'm trying to create a QList of ints and fill them with 0s. I wanted to use resize() but it doesn't seem to be available for Qt5. Is there a workaround or do I have to manually append the list by quite a few times?
-
Thanks a lot, I'm still new, wasn't aware that allocating the space would automatically resize the list.
In regards to manually appending the list, I have the following code:
for (int h = 0; h <= binMantissa.size(); h++){ binMantissa.replace(h, 0); }Is there a better way of doing it in Qt5 or is there a function that replaces all elements of a value?
-
@jsulm reserve does not resize the list :(
@Dummie1138 You might want to use QVector instead, which has resize. In Qt6 QList and QVector are the same anyway.
If not then you'll have to add them one by one e.g. like this, but it's not very efficient for a large n:list.reserve(n); std::fill_n(std::back_inserter(list), n, 0);