I followed the instructions here:

https://gis.stackexchange.com/questions/37111/how-to-install-qgis-on-centos-6

If I run:

QgsVectorLayer * vpoly = new QgsVectorLayer("Polygon", "pointbuffer", "memory");
QgsVectorDataProvider * provider = vpoly->dataProvider();

Then provider is a NULL pointer

Also, if I do:

QString myPluginsDir = "/usr/lib64/qgis";
QgsProviderRegistry * preg = QgsProviderRegistry::instance(myPluginsDir);
QString pluglist=preg->pluginList();
printf("plugins: %s\n",pluglist.toStdString().c_str());

Then it prints:

plugins: No data provider plugins are available. No vector layers can be loaded

Also, when I try to load a QgsVectorLayer with the following:

QgsVectorLayer * mypLayer = new QgsVectorLayer(myLayerPath, myLayerBaseName,    myProviderName);
if (mypLayer->isValid()){
    qDebug("Layer is valid");
} else {
    qDebug("Layer is NOT valid");
    return;
}

Then it says that the layer is NOT valid.

This all works just fine in Ubuntu, but I can't get it to work in centos. I think maybe it's missing all the plugins. What am I missing?

Please help.

有帮助吗?

解决方案

I figured out the problem.

It was unrelated to the code I posted. Heopfully this will be helpful to others that get a similar error.

My code was templated from the QGIS_-Code-Examples (2_basic_main_window)

I didn't change the myPluginsDir variable. Be sure that you change it because by default it will be wrong.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top