I try to test a PyQGIS standalone script which should just show one Shapefile. Sounds pretty simple but does not work.
Here is my script:
from PyQt4 import * from PyQt4 import * from PyQt4.QtCore import * from PyQt4.QtGui import * from qgis.core import * from qgis.gui import * from qgis.utils import * import sys import os qgishome = "C:\OSGeo4W64\apps\qgis" app = QgsApplication(, True) QgsApplication.setPrefixPath(qgishome, True) QgsApplication.initQgis() canvas = QgsMapCanvas() canvas.setCanvasColor(Qt.yellow) canvas.enableAntiAliasing(True) canvas.show() layer = QgsVectorLayer(r"C:/daten/polygons.shp", "Testdaten", "ogr") reg = QgsMapLayerRegistry.instance() reg.addMapLayer(layer) canvas.setExtent(layer.extent()) canvas.setLayerSet([QgsMapCanvasLayer(layer)]) QgsApplication.exitQgis() app.exec_() app.exitQgis()
The Window openes, I can see the yellow background but the Layer is not shown. instad of that there is an error message:
QGraphicsScene::addItem: item has already been added to this scene QObject::connect: Cannot connect (null)::repaintRequested() to QgsMapCanvas::ref resh() QObject::connect: Cannot connect (null)::layerCrsChanged() to QgsMapCanvas::laye rCrsChange()
Sometimes this also brings python to crash, so that a windows error reporting is opened.
I loaded the neccessary environmental variables, which should be ok, as I can import qgis.core and qgis.gui without problems.
does anyone has an idea what's the problem?