class TestModel: public QStandardItemModel { public: explicit TestModel(QWidget* parent):QStandardItemModel(parent) { setColumnCount(5); } virtual ~TestModel() {} void reset() { beginResetModel(); endResetModel(); } }; BOOST_AUTO_TEST_CASE(testEmptyTableView) { QTableView view; view.setSortingEnabled(true); TestModel* model = new TestModel(&view); QSortFilterProxyModel* proxy = new QSortFilterProxyModel(&view); proxy->setSourceModel(model); view.setModel(proxy); BOOST_REQUIRE_EQUAL(proxy, view.model()); BOOST_REQUIRE_EQUAL(5, proxy->columnCount()); BOOST_REQUIRE_EQUAL(0, proxy->rowCount()); QHeaderView* header = view.horizontalHeader(); BOOST_REQUIRE(header); header->moveSection(2, 1); header->setSortIndicator(1, Qt::DescendingOrder); header->resizeSection(3, 20); header->setSectionHidden(3, true); BOOST_REQUIRE_EQUAL(1, header->visualIndex(2)); BOOST_REQUIRE_EQUAL(1, header->sortIndicatorSection()); BOOST_REQUIRE_EQUAL(Qt::DescendingOrder, header->sortIndicatorOrder()); BOOST_REQUIRE(header->isSectionHidden(3)); // simulate a reset model->reset(); BOOST_REQUIRE_EQUAL(5, proxy->columnCount()); BOOST_REQUIRE_EQUAL(0, proxy->rowCount()); BOOST_REQUIRE_EQUAL(1, header->visualIndex(2)); BOOST_REQUIRE_EQUAL(1, header->sortIndicatorSection()); BOOST_REQUIRE_EQUAL(Qt::DescendingOrder, header->sortIndicatorOrder()); BOOST_REQUIRE(header->isSectionHidden(3)); }