[Qgis-developer] acecss to qgisapp / qgisappinterface from tests (c++ or python?)

Martin Dobias wonder.sk at gmail.com
Tue Nov 20 09:08:35 PST 2012


On Tue, Nov 20, 2012 at 5:52 PM, Etienne Tourigny
<etourigny.dev at gmail.com>wrote:

> Hi,
>
> I am trying to add some tests for the addRasterLayer() and
> addVectorLayer() members in QgisApp, and it seems I cannot have access
> to them from the test environment.


>
[...]



How to get the "real" QgsAppInterface like when using a plugin?
>

Hi Etienne

that's right, it's not possible to access QgisAppInterface outside of
running QGIS instance. This has a reason: the interface provides various
methods that make sense only when QGIS is running (e.g. access to map
canvas, main window, toolbars). For testing purposes you could create a
fake implmentation of QgisInterface, but that's most likely not what you
want.

IIRC addVectorLayer() and addRasterLayer() are just relatively simple
wrappers around this code:
layer = new Qgs[Vector / Raster]Layer( ... );
if (layer->isValid())
  QgsMapLayerRegistry::instance()->addMapLayer(layer);

I'm wondering what exactly are you trying to test... is it the "core" layer
(and provider) loading or the connection with other QGIS components?

Regards
Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20121120/60337d2e/attachment.html>


More information about the Qgis-developer mailing list