Bug report #15223

PostgreSQL provider broken under Qt5

Added by Nyall Dawson over 7 years ago. Updated over 6 years ago.

Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:23160


The PostgreSQL provider is broken under Qt5 builds- it is impossible to select a single feature and the attribute table shows all repeating features.

I've tracked this down to QgsPostgresSharedData::lookupFid. Basically, what is happening is that the QMap<QVariant, QgsFeatureId> lookup does not work under Qt5, and in the block:

QMap<QVariant, QgsFeatureId>::const_iterator it = mKeyToFid.constFind( v );

if ( it != mKeyToFid.constEnd() ) {
return it.value();

it will never be constEnd, even when the key is NOT present in the map, it will instead just return the first item in the map. I believe this is due to a broken < operator for QVariant of list types under qt5.

Marking this as a blocker, but not for 2.16

Associated revisions

Revision 46f7c644
Added by Martin Dobias over 7 years ago

Fix postgres pkey map in Qt5 (fixes #15223)

Switching from QVariant to QVariantList solves the underlying Qt issue:
- comparison of QVariantList objects works fine
- comparison of QVariantList objects wrapped in QVariant does not work

The extra wrapping of QVariantList into another QVariant seems unnecessary anyway,
so we may as well save a tiny bit of memory and cpu

Revision 1cb48ddd
Added by Denis Rouzaud over 7 years ago

Merge pull request #3384 from wonder-sk/fix-postgres-qt5

Fix postgres pkey map in Qt5 (fixes #15223)


#1 Updated by Denis Rouzaud over 7 years ago

Found this: http://stackoverflow.com/questions/19703835/qvariant-comparison-with-own-types-working

Is that the difference pointed in Qt doc:

In the case of custom types, their equalness operators are not called. Instead the values' addresses are compared.



Warning: To make this function work with a custom type registered with qRegisterMetaType(), its comparison operator must be registered using QMetaType::registerComparators().


Is this the solution: registering the comparator for QgsFeatureId?

#2 Updated by Nyall Dawson over 7 years ago

I don't think it's that - the key is a QVariantList (not a QgsFeatureId), and it's only for the list-based variant lookup that the map is broken.

#3 Updated by Denis Rouzaud over 7 years ago

  • Status changed from Open to Closed

#4 Updated by Jürgen Fischer over 6 years ago

  • Category set to Unknown

Also available in: Atom PDF