Project

General

Profile

Bug #8378

WStandardItemModel::sort doesn't work when the items are created lazily.

Added by Andreas Frolov 3 months ago. Updated 3 months ago.

Status:
InProgress
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
04/19/2021
Due date:
% Done:

0%

Estimated time:

Description

Hallo,

here is an example that presents incorrect behavior

auto lazyModel = std::make_shared<Wt::WStandardItemModel>(2, 1);

lazyModel->setData(lazyModel->index(0, 0), "2");
lazyModel->setData(lazyModel->index(1, 0), "1");

auto model = std::make_shared<Wt::WStandardItemModel>(2, 1);

model->setItem(0, 0, std::make_unique<Wt::WStandardItem>("2"));
model->setItem(1, 0, std::make_unique<Wt::WStandardItem>("1"));

auto lazyData = Wt::asString(lazyModel->data(lazyModel->index(0, 0))); // "2"
auto data = Wt::asString(model->data(model->index(0, 0))); // "2"

lazyModel->sort(0);
model->sort(0);

auto lazyDataSort = Wt::asString(lazyModel->data(lazyModel->index(0, 0))); // "2" - wrong
auto dataSort = Wt::asString(model->data(model->index(0, 0))); // "1" - ok
#1

Updated by Roel Standaert 3 months ago

  • Description updated (diff)
#2

Updated by Korneel Dumon 3 months ago

  • Status changed from New to InProgress

Our implementation of comparison for cpp17::any apparently does not include const char*. The log actually says it [error] "WAbstractItemModel: unsupported type 'PKc'" (I also overlooked it in the beginning ...)

In the second model, your data is implicitly converted to a WString, so that does work.
As a fix for your example, you can do: lazyModel->setData(lazyModel->index(0, 0), std::string("2"));

I will look into if we can change this, but I image there is a reason why this is not supported. You can also add support in your own code using Wt::registerType()

Also available in: Atom PDF