I have made a few changes here and I do not get a valid layer in the first
place.


        QgsDataSourceURI splUri;
        splUri.setDatabase(spliteDBName);  // i give the database name as a
fully qualified path QString
        splUri.setDataSource("","Trips", ""); // I set the schema and the
geometry to empty? I have a table Trips in the database. 
        QgsVectorLayer* tripLayer = new QgsVectorLayer(splUri.uri(),
"Trips", "spatialite"); // trying to create a vector layer
        if (!tripLayer->isValid())     // ************* I get an invalid layer
here as well
        {
                txtStream<<"Spatialite Layer 
\t"<<tripLayer->name().toStdString()<<"\t is
invalid!"<&lt;endl;
                return;
        } 
      QgsVectorDataProvider* triProv = tripLayer-&gt;dataProvider(); //
invalid provider here
        QgsFeature tripFeat;
        QgsFeatureList tripFeats ;
        QgsAttributeMap tripAttMaps;
        QgsFieldMap tripFldsrc = triProv->fields(); 
        if (tripFldsrc.count()>0)
        {
                i=0;
                for (QgsFieldMap::iterator it = tripFldsrc.begin(); it !=
tripFldsrc.end();it++)
                {
                        tripAttMaps.insert(i++,it->type());
                }

        }
        for (maptrit = maptrip.begin();maptrit != maptrip.end();maptrit++)
        {
                trip = maptrit->second;
                tripFeat.addAttribute(0,trip.get_i());
                tripFeat.addAttribute(1,trip.get_j());
                tripFeat.addAttribute(2,trip.get_v());
                tripFeats.append(tripFeat);
        }
        tripLayer->addFeatures(tripFeats);
        bool blnFeat = tripLayer->commitChanges();
        if (!blnFeat)
        {
                txtStream<<"Failed to commit to Layer
\t"<<tripLayer->name().toStdString()<<endl;
                return;
        }



--
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Load-SQLite-table-into-QGIS-tp6876536p6893817.html
Sent from the qgis-developer mailing list archive at Nabble.com.
_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to