[Qgis-developer] some trouble with pointers in my c++-plugin

SSchmidt at gfi-gis.de SSchmidt at gfi-gis.de
Tue Dec 10 03:19:18 PST 2013


Hello all,

I asked the question on stackexchange but nobody could help me. I think 
it's a beginner-problem but I can't get it. Maybe somenone here could help 
me please?

I want to set the extent of my map for two cases. In one case i have the 
geometry as QGsGeometry* in my object of class "adress", in other case i 
use the coordinates also from my object as double-values. Setting the 
extent from geometry works fine, in the other case QGis crashes by 
refresh(). I think qgis wants to give my adress->x/y free. where is my 
error? I'll get the pointeritis! Here is my code:
QgsRectangle* extent;
    QgsPoint pt;
    double myX=(adress->X);
    double myY(adress->Y);
    if (adress->geom==0)
    {
        pt=QgsPoint(myX,myY);
        qDebug()<<"Geom is 
null"<<"X="<<QString::number(pt.x())<<"Y="<<QString::number(pt.y());
    }
    else
    {
        pt = adress->geom->asPoint();
        qDebug()<<"Geom is 
valid"<<"X="<<QString::number(pt.x())<<"Y="<<QString::number(pt.y());
    }
    extent= new QgsRectangle( pt.x() - 50.0,  pt.y() - 50.0, pt.x() + 
50.0,  pt.y() + 50.0);
    mQGisIface->mapCanvas()->setExtent(*extent);
    mQGisIface->mapCanvas()->refresh();

And this are the messages:
Geom is null X= "4.45099e+06" Y= "5.71994e+06" Eine Ausnahme (erste 
Chance) bei 0x5e453fe6 in qgis-bin.exe: 0xC0000005: Zugriffsverletzung 
beim Lesen an Position 0x0000000c. Unbehandelte Ausnahme bei 0x5e453fe6 in 
qgis-bin.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 
0x0000000c.

Freundliche Grüße aus Leipzig
Susann Schmidt
Softwareentwicklung 

**************************************************************

GFI - Gesellschaft für Informationstechnologie mbH
Philipp-Rosenthal-Straße 9
D-04103 Leipzig
Geschäftsführer: Andreas Richter
Amtsgericht Leipzig HRB 12054
USt.-IdNr.: DE179049354     Steuer-Nr.: 231/109/06412
ESRI Solution Partner      und       ER Mapper Reseller
Tel. 0341 961 3310    Fax 0341 961 3311   Mail info at gfi-gis.de
Web  www.gfi-gis.de  und  www.themenbrowser.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20131210/0d24cf20/attachment-0001.html>


More information about the Qgis-developer mailing list