[Interest] Why doesn't my model filter update?

Matthew Woehlke mwoehlke.floss at gmail.com
Tue Feb 18 22:49:57 CET 2020

On 18/02/2020 16.31, Konstantin Shegunov wrote:
> On Tue, Feb 18, 2020 at 11:20 PM Matthew Woehlke wrote:
>> I wonder if anyone else can spot it? ;-)
> Without knowing anything about the code at all, my best guess based on a
> very quick glance would be the range for the dataChanged is wrong.

Okay, I'll give you half a cookie, since I can't really say much more
without giving it away. (Incidentally, if I hadn't already figured it
out, you comment probably would have helped!)

Here's the broken code:

  if (auto const rows = this->rowCount())
    auto const& first = this->index(0, 0);
    auto const& last = this->index(rows, 0);

    emit this->dataChanged(first, last, {MyFilterRole});

It fell victim to one of the two hard problems of programming (as
enumerated by Leon Bambrick┬╣). To wit, `last` is an invalid index, which
trips one of the sanity checks in QSortFilterProxyModel's internal logic.

If you can't tell *why* `last` is invalid, well, keep looking until you
can ;-). All the information you need to spot the problem is in the
above snippet, and it's *obvious* once you see it. (Note: assume that
the class otherwise behaves in a correct fashion.)

(┬╣ https://www.goodreads.com/quotes/7443069)


More information about the Interest mailing list