From d315a12362714703b273f062e8f9a9cb342c4289 Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Thu, 19 Nov 2015 15:24:46 +0100 Subject: [PATCH] Fix segfault when editor widget is invalid on form init "editor" can be null in that case --- .../core/qgseditorwidgetregistry.cpp | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp b/src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp index a351bed87961..c54f34ccf78b 100644 --- a/src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp +++ b/src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp @@ -351,23 +351,28 @@ QString QgsEditorWidgetRegistry::findSuitableWrapper( QWidget* editor, const QSt QMap >::ConstIterator it; QString widgetid; - int weight = 0; - - it = mFactoriesByType.constBegin(); - for ( ; it != mFactoriesByType.constEnd(); ++it ) + + // Editor can be null + if ( editor ) { - if ( editor->staticMetaObject.className() == it.key() ) - { - // if it's a perfect match: return it directly - return it.value().second; - } - else if ( editor->inherits( it.key() ) ) + int weight = 0; + + it = mFactoriesByType.constBegin(); + for ( ; it != mFactoriesByType.constEnd(); ++it ) { - // if it's a subclass, continue evaluating, maybe we find a more-specific or one with more weight - if ( it.value().first > weight ) + if ( editor->staticMetaObject.className() == it.key() ) + { + // if it's a perfect match: return it directly + return it.value().second; + } + else if ( editor->inherits( it.key() ) ) { - weight = it.value().first; - widgetid = it.value().second; + // if it's a subclass, continue evaluating, maybe we find a more-specific or one with more weight + if ( it.value().first > weight ) + { + weight = it.value().first; + widgetid = it.value().second; + } } } }