Priority: Not Evaluated
Affects Version/s: 6.2.0, 6.3.2
Fix Version/s: None
I've been using a table model with a sort/filter model in PySide6 and ran into a problem where integers are sorted incorrectly, and somewhat unpredictably.
It looks like the sorting problem occurs on the C++ side, in the following function:
Adding some print debugging to the Python side, it first looked like an obvious case of everything being compared as signed 32-bit integers:
However, as I mentioned the sorting being unpredictable, other values seemed to be compared correctly:
Looking back at the C++ code, I realized the switch only checks "left.userType()", so the issue seems to be that when the left value is small enough to fit into a signed 32-bit integer, the larger value accidentally gets converted to one as well.
I haven't used Qt in C++ and don't know how QVariants behave there, but I'm guessing you'll be more aware of your integer types and there's no implicit conversion like this, so I'm reporting this as a PySide/Shiboken bug.
I've attached a small example which should demonstrate the issue in a table view. I commented out the print statements (lines 44-53) since the output is somewhat verbose, but they're there just in case.
I originally spotted the issue with PySide 6.3.1 and confirmed it with 6.3.2. I also downgraded to 6.2.0 and the same thing occurs, so it doesn't seem to be a recent regression.
I realize there's an easy workaround by just doing your own sorting in lessThan() and avoiding the C++ calls altogether, but it feels like a "gotcha" for integers which aren't anywhere near breaking 64-bit limits.