[Qgis-developer] Need help with LayerTreeModel (legend node)

Sandro Santilli strk at keybit.net
Wed Dec 17 06:34:47 PST 2014


On Wed, Dec 17, 2014 at 01:13:31PM +0100, Sandro Santilli wrote:
> In the "wmslegend" branch of my fork [1] I've a working wms legend node
> that fetches the actual legend image lazily from the Model's data() method
> when it is invoked with the role = Qt::DecorationRole.
> 
> But for some reason, if I also attempt to load the legend when data() method
> is invoked with role = Qt::SizeHintRole, all kind of weird behavior happen,
> like crashes or hangs.

Further analisys.

The internal QEventLoop used by QgsWmsCapabilitiesDownload
(in downloadCapabilities method) receives events from the LayerTree
QTreeView which gets to call the legend node's data() with SizeHintRole (13)

 #2  0x00007ffff4009c55 in QgsWMSLegendNode::data (this=0x3bd3b50, role=13)
 [..]
 #4  0x00007ffff24cd97c in QStyledItemDelegate::sizeHint(QStyleOptionViewItem const&, QModelIndex const&) const ()
 [..]
 #12 0x00007ffff2476e8a in QTreeView::timerEvent(QTimerEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
 [..]
 #30 0x00007ffff2b9d3a5 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
 #31 0x00007fff7143d5ae in QgsWmsCapabilitiesDownload::downloadCapabilities (this=0x7fffffffabf0)

That first ::data() call, calls QgsWmsProvider::getLegendGraphic, for lazy
download. That call, in turn, creates a second QEventLoop, which gets
to process another event from the QTreeView timer event:

A second call to ::data() arrives from an event processed by the
loop started internally to QgsWmsProvider::getLegendGraphics, again
with SizeHint:

 #2  0x00007ffff4009c55 in QgsWMSLegendNode::data (this=0x3bd3b50, role=13)
 [..]
 #36 0x00007ffff2b9d3a5 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
 #37 0x00007fff71472976 in QgsWmsProvider::getLegendGraphic (this=0x3b66ae0, scale=0, forceRefresh=true, visibleExtent=0x7fffffff9a80)

Then another arrives, with DecorationRole this time, from the same event.
Finally a new one arrives from main loop and triggers a segfault.

I'm wondering if we should avoid to use internal QEventLoops completely.
They do look like hacks meant to implement blocking operations, which
we'd better not have after all, right ?

--strk;

 ()  ASCII ribbon campaign  --  Keep it simple !
 /\  http://strk.keybit.net/rants/ascii_mails.txt  


More information about the Qgis-developer mailing list