[Qgis-developer] Tracing errors of the vector layer creation

Martin Dobias wonder.sk at gmail.com
Sat Apr 30 12:29:08 EDT 2011


Hi "Eye OnNet"

On Sun, Apr 24, 2011 at 6:34 PM, Eye OnNet <eyeonnet2001 at yahoo.com> wrote:
> Hello.
>
> In my application I execute a simple sequence of QGIS API functions for create vector layer from postgres database:
>
>  QgsDataSourceURI uri = QgsDataSourceURI();
>  uri.setConnection(ServerIP,port,dbname,username,password);
>  uri.setDataSource(scheme,table,geom,sql);
>  QgsVectorLayer *vlayer = new QgsVectorLayer(uri.uri(),"layername", "postgres");
>  if(!vlayer->isValid())qDebug(vlayer->lastError()+vlayer->lastErrorTitle());
>
> "isValid()" check failed in application on the one polygon layer but the QGIS opens this layer successful without an error. Both "lastError()" and "lastErrorTitle()" return an empty string... How do to recognize cause of that error?

The lastError() method is currently used for showing errors from
rendering, not from layer load stage. When the layer fails to load,
usually a QgsMessageOutput class is used to send a message to the user
about the cause. In QGIS application a dialog pops up with the
message. If you are developing a custom application, the default
behavior is to print this to console. It is possible to set a custom
message handler in order to process these errors in an appropriate
way.

Martin

Do you run this code


More information about the Qgis-developer mailing list