short

Sort a QRangeModel in Qt 6.12 without a proxy model

· english· audience: working-cpp· AI-generated, reviewed by Filip Sajdak

On Compiler Explorer, Qt 6.12.0 sorts a std::vector of rows through QRangeModel. The same program built against Qt 6.11.0 leaves the rows in their original order. Qt 6.12 is a Long-Term Support release, published on 30 September 2026. The EU Cyber Resilience Act side of that release is in the October post.

Sorting rows in the model

QRangeModel wraps a C++ range so that Qt views can show it. The 6.12 documentation adds a sort() override. It also adds the sortRole and sortCollator properties.

The documentation says sort() calls a member sort() of the range when one exists. Otherwise it calls std::stable_sort() for random-access ranges, and for any other range it does nothing.

The demo wraps a vector of std::tuple<QString, int>, which the documentation lists as a table row. It prints the rows, calls model.sort(1, Qt::DescendingOrder) and prints them again.

The run exits with 0 and prints the rows in the order GCC 5, MSVC 4, Clang 3, EDG 2. The Qt 6.11.0 run of the same source prints Clang, GCC, MSVC, EDG after the call.

The documentation also lists a new match() override. The release post calls it faster searching, and I did not measure it. The documentation adds that an application compiled against Qt 6.11 does not call either override, even on Qt 6.12. Recompile to get them.

Other changes in the release

Area What the Qt pages say
Canvas Painter The core API leaves Technology Preview and is ready for production for C++ and QML. The Canvas2D element and the custom brush class stay in preview.
QtGrpc Client-side request compression, with Identity, Deflate and Gzip choices, and a cap on incoming message size.
LTS Maintenance over a 5-year period, with a new LTS release every 2 years.

The C++ standard

The C++20 overview page says Qt 6 officially requires C++17. Qt WebEngine needs a C++20 compiler. The three-way comparison operator on QtCore classes works only when the user project builds in C++20 mode.

The demo compiled at -std=c++17. For earlier Qt work on this site, see the moc-free examples post.

What this has not been tested on

  • Qt 6.12 outside Compiler Explorer, any compiler except GCC 16.2, and any GUI view.
  • The match() speedup. The demo also leaves the sort role and the collator at their defaults.
  • Canvas Painter and QtGrpc. I read their pages and ran no code.
  • Whether reflect-moc works with Qt 6.12. The posts about it used Qt 6.10.3, and I did not try 6.12.
  • The end date of the 5-year period, which the pages I read do not give.

Sources, all read on 12 October 2026 and read again on 18 October 2026, with the same content. I also ran both Compiler Explorer sessions again on 18 October and they printed the same rows: