<div dir="ltr"><div>It works for me!</div><div><br></div><div><br></div><div><br></div><div> QString uri = "crs=EPSG:4326&featureCount=10&format=image/gif&layers=osm_auto:all&styles=&url=<a href="http://129.206.228.72/cached/osm">http://129.206.228.72/cached/osm</a>";</div>
<div> QgsRasterLayer *rlayer = new QgsRasterLayer(uri, "layer_name", "wms", false);</div><div> qDebug() << "layer is valid:" << rlayer->isValid();</div><div><br></div><div>
connect( rlayer, SIGNAL(repaintRequested()), mapCanvas, SLOT(refresh()) );</div><div> </div><div> QgsMapLayerRegistry::instance()->addMapLayer(rlayer);</div><div> </div><div> QList <QgsMapCanvasLayer> myLayerSet;</div>
<div> myLayerSet.append(QgsMapCanvasLayer(rlayer, true));</div><div> //</div><div> mapCanvas->setExtent(rlayer->extent());</div><div> mapCanvas->enableAntiAliasing(true);</div><div> mapCanvas->freeze(false);</div>
<div> mapCanvas->setLayerSet(myLayerSet);</div><div> mapCanvas->setVisible(true);</div><div> mapCanvas->refresh();</div><div><br></div><div><br></div></div>