[Qgis-developer] [Plugin] Catch click mouse events

Olivier Tournaire olitour at gmail.com
Sun Dec 28 10:32:28 EST 2008


Hi all,

I am currently trying to write a plugin for QGis. I just need a simple
thing: be able to catch click events. So, I just added in my plugin this
piece of code:

// plugin.hpp
// ...
QgsMapToolEmitPoint* m_toolEmitPoint;
// ...
private slots:
   // ...
   void canvas_clicked(QgsPoint &point, Qt::MouseButton button);

// plugin.cpp
// in the constructor
m_toolEmitPoint = new QgsMapToolEmitPoint(m_mapCanvas);
QObject::connect( (QgsMapToolEmitPoint*)m_toolEmitPoint ,
SIGNAL(canvasClicked()) , this ,
SLOT(canvas_clicked(QgsPoint&,Qt::MouseButton)) );
// I also tried this version, but it does not work better:
QObject::connect( (QgsMapToolEmitPoint*)m_toolEmitPoint ,
SIGNAL(canvasClicked(QgsPoint&,Qt::MouseButton)) , this ,
SLOT(canvas_clicked(QgsPoint&,Qt::MouseButton)) );

void plugin::canvas_clicked(QgsPoint &point, Qt::MouseButton button)
{
    QMessageBox msg;
    msg.setText("Canvas clicked !");
    msg.exec();
}

The problem is that with the above code, the function canvas_clicked is
never called. So, what am I doing wrong ? Do I misunderstand how to use
QgsMapToolEmitPoint ?

Could please help me ?

Best regards,

Olivier

-- 
Olivier Tournaire
MATIS - Institut Géographique National
73, Ave de Paris
94165 St Mandé cedex, France

tel: (+33) 1 43 98 80 00 - 71 25
fax: (+33) 1 43 98 85 81
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20081228/4e9b21c8/attachment.html


More information about the Qgis-developer mailing list