[Qgis-developer] run QGIS C++ application "Failed to load"
xmayyang
xmayyang at gmail.com
Wed Jan 8 17:29:44 PST 2014
I download code_examples from svn,and build the
"1_hello_world_qgis_style".When I run it, it failed.
fail message:
Failed to load
Layer is NOT valid
QObject::connect: Cannot connect (null)::repaintRequested() to
QgsMapCanvas::refresh()
QObject::connect: Cannot connect (null)::screenUpdateRequested() to
QgsMapCanvas::updateMap()
I build and install qgis in /usr/local.
This is my cmake configration:
CMAKE_BUILD_TYPE
CMAKE_INSTALL_PREFIX /usr/local
GDAL_CONFIG /usr/local/bin/gdal-config
GDAL_CONFIG_PREFER_PATH /bin
GDAL_INCLUDE_DIR /usr/local/include
GDAL_LIBRARY /usr/local/lib/libgdal.so
GEOS_INCLUDE_DIR /usr/include/geos
GEOS_LIBRARY /usr/lib/libgeos_c.so
QGIS_CORE_LIBRARY /usr/local/lib/libqgis_core.so
QGIS_GUI_LIBRARY /usr/local/lib/libqgis_gui.so
QGIS_INCLUDE_DIR /usr/local/include/qgis
QGIS_PLUGIN_DIR /usr/local/lib/qgis
QT_QMAKE_EXECUTABLE /usr/bin/qmake
the code:
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgssinglesymbolrenderer.h>
#include <qgsmaplayerregistry.h>
#include <qgsvectorlayer.h>
#include <qgsmapcanvas.h>
#include <QString>
#include <QApplication>
#include <QWidget>
int main(int argc, char ** argv)
{
QgsApplication app(argc, argv, true);
QString myPluginsDir = "/usr/local/lib/qgis/";
QString myLayerPath = "/dev/cpp/shape/bou1_4l";
QString myLayerBaseName = "bou1_4l";
QString myProviderName = "ogr";
QgsProviderRegistry::instance(myPluginsDir);
QgsVectorLayer * mypLayer = new QgsVectorLayer(myLayerPath,
myLayerBaseName, myProviderName);
QgsSingleSymbolRenderer *mypRenderer = new
QgsSingleSymbolRenderer(mypLayer->geometryType());
QList <QgsMapCanvasLayer> myLayerSet;
mypLayer->setRenderer(mypRenderer);
if (mypLayer->isValid())
{
qDebug("Layer is valid");
}
else
{
qDebug("Layer is NOT valid");
}
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer, TRUE);
myLayerSet.append(QgsMapCanvasLayer(mypLayer, TRUE));
QgsMapCanvas * mypMapCanvas = new QgsMapCanvas(0, 0);
mypMapCanvas->setExtent(mypLayer->extent());
mypMapCanvas->enableAntiAliasing(true);
mypMapCanvas->setCanvasColor(QColor(255, 255, 255));
mypMapCanvas->freeze(false);
mypMapCanvas->setLayerSet(myLayerSet);
mypMapCanvas->setVisible(true);
mypMapCanvas->refresh();
return app.exec();
Is there somebody help me?Thank you very much.
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/run-QGIS-C-application-Failed-to-load-tp5097056.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
More information about the Qgis-developer
mailing list