[Qgis-developer] Qgis standalone apps

Giuseppe Sucameli brush.tyler at gmail.com
Thu Sep 9 20:07:22 EDT 2010


Hi Massimo,

On Fri, Sep 10, 2010 at 12:10 AM, Massimo Di Stefano <
massimodisasha at yahoo.it> wrote:

> Hi All,
>
> i'm tring to start some coding on the qgis api
> i'm on osx 10.6.4 running qgis 1.6
>
> following the example from :
>
>
>
> http://mapserver.sk/~wonder/qgis/html/canvas.html#using-map-tools-with-canvas<http://mapserver.sk/%7Ewonder/qgis/html/canvas.html#using-map-tools-with-canvas>
>
> it works fine if i call it from a qgis-python shell
>
> but i tried to make small changes to have it running as a standalone
> application,
>
> i eliminated the "layer" from the init line :
>
> QMainWindow.__init__(self)
>
> used a custom extent :
>
> self.canvas.setExtent('15.1845401903089403,40.6214856769878665 :
> 15.2339879807105998,40.6477493100907381')
>
> and commented out the line :
>
> #self.canvas.setLayerSet( [ QgsMapCanvasLayer(layer) ] )
>
> then from a standard python shell, i tried :
>
> >>> import mywnd
> >>> dir(mywnd)
> ['MyWnd', 'QAction', 'QMainWindow', 'QString', 'QgisInterface',
> 'QgsAnnotationItem', 'QgsColorButton', 'QgsColorButtonV2',
> 'QgsComposerView', 'QgsEncodingFileDialog', 'QgsFormAnnotationItem',
> 'QgsGenericProjectionSelector', 'QgsLegendInterface', 'QgsMapCanvas',
> 'QgsMapCanvasItem', 'QgsMapCanvasLayer', 'QgsMapCanvasMap',
> 'QgsMapCanvasSnapper', 'QgsMapOverviewCanvas', 'QgsMapTip', 'QgsMapTool',
> 'QgsMapToolEmitPoint', 'QgsMapToolPan', 'QgsMapToolZoom',
> 'QgsMessageViewer', 'QgsProjectBadLayerGuiHandler', 'QgsProjectionSelector',
> 'QgsQuickPrint', 'QgsRendererV2PropertiesDialog', 'QgsRendererV2Widget',
> 'QgsRubberBand', 'QgsStyleV2ManagerDialog', 'QgsSymbolLayerV2Widget',
> 'QgsSymbolV2PropertiesDialog', 'QgsSymbolV2SelectorDialog',
> 'QgsTextAnnotationItem', 'QgsVertexMarker', 'Qt', 'SIGNAL', '__builtins__',
> '__doc__', '__file__', '__name__', '__package__']
> >>> w = mywnd.MyWnd()
> QWidget: Must construct a QApplication before a QPaintDevice
> Abort trap
>
the MyWnd is a QWidget.

You must create a QApplication instance and only after this you can
show widgets within it.

Here an example (main.py):


from PyQt4.QtGui import QApplication
from mywdg import MyWdg

class MainApp(QApplication):
    def __init__(self, args):
        QApplication.__init__(self, args)
        wdg = MyWdg()
        wdg.show()
        self.exec_()

if __name__ == "__main__":
        import sys
    app = MainApp(sys.args)


Then open a terminal and run: python main.py
and if all went fine you can see your widget.

Cheers.


>
> it give me a python crash ... obviously i'm missing something basilar,
>
> have you any clue on what i need to change to have the example working
> outside qgis ?
>
>
> thanks a lot !!!
>
> regards,
>
> Massimo
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>



-- 
Giuseppe Sucameli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20100910/7ebd988c/attachment-0001.html


More information about the Qgis-developer mailing list