[QGIS-Developer] Does QgsProject.instance().createEmbeddedGroup() work?

Johannes Kröger (WhereGroup) johannes.kroeger at wheregroup.com
Mon Sep 19 00:08:02 PDT 2022


Hi Alister,

https://qgis.org/pyqgis/master/core/QgsProject.html#qgis.core.QgsProject.createEmbeddedGroup 
and 
https://api.qgis.org/api/classQgsProject.html#ad2e059da29ebfc32096367abb78da46c 
say it should return a QgsLayerTreeGroup so I guess it is broken, at 
least documentation-wise.

https://api.qgis.org/api/qgsproject_8cpp_source.html#l03274 on the other 
hand hints at several "return nullptr" so it returning None is by 
design. The code seems fairly readable and even has useful comments so 
maybe check if one of the cases might be true in your testcase.

Cheers, Hannes

Am 19.09.22 um 05:40 schrieb Alister Hood via QGIS-Developer:
> Hi, I want to programmatically embed a project, like I can in the gui 
> with "Layer>embed layers and groups."
>
> I thought QgsProject.instance().createEmbeddedGroup() was what I 
> needed, but it doesn't seem to work - see below.  Am I completely off 
> track, or is it broken?
>
> Thanks.
>
> path='/home/alister/testtoembed.qgs'
> project = QgsProject.instance()
> project.read(path)
> True
> project.clear()
> newGroup = QgsLayerTreeGroup()
> type(newGroup)
> <class 'qgis._core.QgsLayerTreeGroup'>
> newGroup = QgsProject.instance().createEmbeddedGroup('test', path, [])
> type(newGroup)
> <class 'NoneType'>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

-- 
Johannes Kröger / GIS-Entwickler/-Berater

---------------------------------------------
Schon gewusst?
In unserem Blog geben wir Tipps & Tricks zu Open-Source-GIS-Software
und berichten aus unserem Experten-Alltag:
https://wheregroup.com/blog/
---------------------------------------------

WhereGroup GmbH
Grevenweg 89
20537 Hamburg
Germany

Tel: +49 (0)228 / 90 90 38 - 36
Fax: +49 (0)228 / 90 90 38 - 11

johannes.kroeger at wheregroup.com
www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
-------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x840A4B843789797F.asc
Type: application/pgp-keys
Size: 2472 bytes
Desc: OpenPGP public key
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220919/b8e65b85/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 665 bytes
Desc: OpenPGP digital signature
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220919/b8e65b85/attachment.sig>


More information about the QGIS-Developer mailing list