title: Qt RTTI trouble
body: <p>In a quest for handling events (like mouse moves and clicks) not by subclassing, one has to use <code>installEventFilter</code> and provide an event handler. While doing so, I've encountered a problem with RTTI support, meaning that <code>typeid().name()</code> gives <code>QObject *</code> all the time, no matter on which object event was triggered. There is, of course, another solution---<code>dynamic_cast</code> followed by null-pointer check, but personally I don't find it clean (and would like to avoid multiple such checks).
  To be more specific, here is an example I didn't make to work with Visual C++ with RTTI enabled (/GR):</p>
  
  <pre><code>bool
  MousePressInterface::eventFilter
      (QObject *obj,
      QEvent *event)
  {
      if (event-&gt;type() == QEvent::MouseButtonPress)
      {
          ColorPicker *sender;
          sender = dynamic_cast&lt;ColorPicker *&gt; (obj);
  
          if ( sender )
          {
              QColor newColor = 
                  QColorDialog::getColor(sender-&gt;color());
              if ( newColor.isValid() )
                          sender-&gt;setColor( newColor );
              Logger::log("color picker clicked");
              return true;
          }
  /* TODO: cleaner way, doesn't work for some reason!
          Logger::log(QString("mouse pressed on %1").arg(typeid(obj).name()));
          Logger::log(QString(" checking for %1").arg(typeid(ColorPicker *).name()));
  
          if ( typeid(obj) == typeid(ColorPicker * ) )
              Logger::log("color picker clicked");
  */
      }
  </code></pre>