Discussion:
Open a *.qgs project file in API, why maps do not show?
Tendfly niu
2014-10-21 02:10:25 UTC
Permalink
Hi all,
I'm using QGIS-2.4.0 API. I saved a test.qgs file in QGIS Desktop, in this
project, there is one layer in it.

Then I open the test.qgs project file in QGIS API to developing, but it is
not showed in APP.

Why is that?
The code I'm using to open the project is:
QString myProjectPath = "E:\\QGIS\\Pro\\test.qgs";
Qgsproject::instance()->setFileName(myProjectPath);
bool isRead = QgsProject::instance()->read();

In Debug mode, isRead equals TRUE.

Any advice would be appreciated!



Regards,



Bob
Gary Sherman
2014-10-21 02:18:40 UTC
Permalink
Post by Tendfly niu
Hi all,
I'm using QGIS-2.4.0 API. I saved a test.qgs file in QGIS Desktop, in
this project, there is one layer in it.
Then I open the test.qgs project file in QGIS API to developing, but it
is not showed in APP.
Why is that?
QString myProjectPath = "E:\\QGIS\\Pro\\test.qgs";
Qgsproject::instance()->setFileName(myProjectPath);
bool isRead = QgsProject::instance()->read();
In Debug mode, isRead equals TRUE.
Use:

iface.addProject(myProjectPath)
Post by Tendfly niu
Any advice would be appreciated!
Regards,
Bob
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Gary Sherman

Founder, QGIS Project
Consulting: geoapt.com
Publishing: locatepress.com

We work virtually anywhere
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spartucus
2014-10-21 02:24:53 UTC
Permalink
Hi Gary ,
Thanks for reply!
I don't what iface is. Is it another name of QgsProject::instance()? I'm
using C++ to developing app.



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Open-a-qgs-project-file-in-API-why-maps-do-not-show-tp5168545p5168547.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
Gary Sherman
2014-10-21 02:34:22 UTC
Permalink
Post by Spartucus
Hi Gary ,
Thanks for reply!
I don't what iface is. Is it another name of QgsProject::instance()? I'm
using C++ to developing app.
Ah, I missed the fact you were using C++.

iface is an instance of QgisInterface available in the Python console.
It exposes interfaces in QgisApp, which doesn't help you if you are
developing a standalone app in C++.

See the code for: QgisApp::addProject( QString projectFile ) in
qgisapp.cpp for how QGIS loads a project file.
Post by Spartucus
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Open-a-qgs-project-file-in-API-why-maps-do-not-show-tp5168545p5168547.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
_______________________________________________
Qgis-developer mailing list
http://lists.osgeo.org/mailman/listinfo/qgis-developer
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Gary Sherman

Founder, QGIS Project
Consulting: geoapt.com
Publishing: locatepress.com

We work virtually anywhere
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spartucus
2014-10-21 02:37:26 UTC
Permalink
Thanks a lot! I will try that.



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Open-a-qgs-project-file-in-API-why-maps-do-not-show-tp5168545p5168549.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
Spartucus
2014-10-21 13:00:10 UTC
Permalink
Hi Gary,
According to the QgisApp::addProject( QString projectFile ) function, I did
some change in my code. However, the map still doesn't show, but the CRS in
project works fine. So I think the project file was read but there is
something wrong about display(or MapCanvas).

I don't use Python plug-ins and ScaleComboBox, so I remove the relevant
part, the code is:




--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Open-a-qgs-project-file-in-API-why-maps-do-not-show-tp5168545p5168673.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
Loading...