[Qgis-developer] New QGis project, application : version is empty and wms layer invalid

chrome2006-dev at yahoo.com chrome2006-dev at yahoo.com
Sun Oct 6 10:32:24 PDT 2013



Hi


This is my first attemp with QGIS. I'm using 2.0 version.
My first goal is a proof of concept with a wms map and a vector map.
I started with the wms service. You'll find the code below, there are two
things that don't go well.

First, QgsApplication::applicationVersion() is "", Did I do something wrong in 

initialization ?


Second, my wms layer is not valid but maybe it is only because of the first question...



main.cpp
int main(int argc, char *argv[])
{
    QgsApplication app(argc, argv, TRUE);
    MainWindow w;
    w.show();
    
    return app.exec();
}



mainwindow.cpp

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QgsApplication::setPrefixPath("/usr/lib/qgis", false);
    QgsApplication::initQgis();
    qDebug()<<
 QgsApplication::applicationVersion();     // <<------------------- return empty string

    mapCanvas = new QgsMapCanvas(this);
    mapCanvas->enableAntiAliasing(true);
    mapCanvas->useImageToRender(false);
    mapCanvas->setCanvasColor(QColor(255, 255, 255));
    mapCanvas->freeze(false);
    mapCanvas->setVisible(true);
    mapCanvas->refresh();
    mapCanvas->show();

    QVBoxLayout* lyt = new QVBoxLayout(ui->centralWidget);
    lyt->addWidget(mapCanvas);

    QString uri = "crs=EPSG:4326&featureCount=10&format=image/gif&layers=osm_auto:all&styles=&url=http://129.206.228.72/cached/osm";
    QgsRasterLayer* rlayer = new  QgsRasterLayer(uri, "test",
 "wms", true);
    if (!rlayer->isValid()) qDebug() <<"invalid wms";   // <<--------------------- It is invalid !

    QgsMapLayerRegistry::instance()->addMapLayer(rlayer);

    mapCanvas->layers().append(rlayer);
    mapCanvas->zoomScale(1/10000);
    mapCanvas->centerOn(5.7, 45.2);
    mapCanvas->update();
}

Thanks for your help.
Regards
Juliette
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20131006/cf0ebaf7/attachment-0001.html>


More information about the Qgis-developer mailing list