[Qgis-user] How to load a *.qgs file in a C++ QGIS standalone app?

Matthias Kuhn matthias.kuhn at gmx.ch
Tue Oct 28 00:56:31 PDT 2014


Hi Spartucus,

QgsLayerTreeMapCanvasBridge should help you there

header:
   QgsLayerTreeMapCanvasBridge* mLayerTreeCanvasBridge;

source:
   mLayerTreeCanvasBridge = new QgsLayerTreeMapCanvasBridge( 
QgsProject::instance()->layerTreeRoot(), mMapCanvas, this );
   QgsProject::instance()->read( path_to_your_project_file );

I hope that helps,
Matthias


On 10/28/2014 01:52 AM, Spartucus wrote:
> I'm using QGIS-2.4.0 API to develop a standalone app by C++.
> I saved a test.qgs file in QGIS Desktop software, in the project, there was
> one layer and it was visible.
> Then I loaded the test.qgs project file in app, but there is nothing showed.
> Why is that?
>
> The code I'm using to open the project is:
> QgsApplication app(argc, argv, true);
> QString myQgisDir = "C:\\Program Files(x86)\\qgis2.4.0";
> app.setPrefixPath(myQgisDir, true);
> app.initQgis();
>
> //The set of mapcavas
> QgsMapCanvass *myMapCanvas = new QgsMapCanvas();
> myMapCanvas->enableAntiAliasing(true);
> myMapCanvas->setCanvasColor(Qt::white);
> myMapCanvas->setVisiable(true);
>
> //Open *.qgs project and read
> QString myProjectPath = "E:\\QGIS\\Pro\\test.qgs";
> Qgsproject::instance()->setFileName(myProjectPath);
> bool isRead = QgsProject::instance()->read();    //In Debug mode, isRead
> equals TRUE.
>
> Can somebody help me out? Any advice would be appreciated!
>
>
>
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/How-to-load-a-qgs-file-in-a-C-QGIS-standalone-app-tp5169813.html
> Sent from the Quantum GIS - User mailing list archive at Nabble.com.
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user

-- 
--------------------------------------

Please help taking QGIS to the next level of quality. Before November 15 !
http://blog.vitu.ch/10102014-1046/crowdfunding-initiative-automated-testing




More information about the Qgis-user mailing list