Bug report #15223

PostgreSQL provider broken under Qt5

Added by Nyall Dawson over 8 years ago. Updated about 7 years ago.

Status:Closed
Priority:Severe/Regression
Assignee:-
Category:Unknown
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

Description

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 8 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 8 years ago

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

Fix postgres pkey map in Qt5 (fixes #15223)

History

#1 Updated by Denis Rouzaud over 8 years ago

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

Is that the difference pointed in Qt doc:
Qt4:

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

http://doc.qt.io/qt-4.8/qvariant.html#operator-eq-eq

Qt5:

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

http://doc.qt.io/qt-5/qvariant.html#operator-eq-eq

Is this the solution: registering the comparator for QgsFeatureId?
http://doc.qt.io/qt-5/qmetatype.html#registerComparators

#2 Updated by Nyall Dawson over 8 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 8 years ago

  • Status changed from Open to Closed

#4 Updated by Jürgen Fischer about 7 years ago

  • Category set to Unknown

Also available in: Atom PDF