QObject method children returns empty list.



  • I reimplement the QApplication's method notify to handle some key events. The task is to block all event handlers of it and make it i one place, but not for all QObjects. I mean I have some objects when I need to handle it by standard event handler. So there is the code:
    @public: bool notify(QObject * obj, QEvent * event) {

    const QMetaObject * objMeta = obj->metaObject();
    QString clName = objMeta->className();
    
    bool bProceed = false;
    bool bisWidgetWindow = (obj->children().isEmpty() == false);
    
    if (event->type() == QEvent::KeyPress) {     
    
     QKeyEvent * keyEvent = static_cast <QKeyEvent *>(event);
     
     if (bisWidgetWindow == false && obj->inherits("QTextEdit") == false)
      bProceed = onKeyPress(keyEvent);     
    
    } else if (event->type() == QEvent::KeyRelease) {
    
     QKeyEvent * keyEvent = static_cast <QKeyEvent *>(event);
     
     if (bisWidgetWindow == false && obj->inherits("QTextEdit") == false)
      bProceed = onKeyRelease(keyEvent);
     
    } else
     bProceed = true;    
    
    if (bProceed)
     return QApplication::notify(obj, event);  
    
    if (bisWidgetWindow)
     return QApplication::notify(obj, event); 
    
    if (obj->inherits("QTextEdit"))
     return QApplication::notify(obj, event); 
    
    return false;
    

    }@
    And the methods that handles keyEvent:
    @private slots : bool onKeyPress(QKeyEvent * event) { // returns true if need to call standard event handler

         if (event->key() == Qt::Key_Space) {
    
       emit spaceBarPressed();
       return false;
      }
    
      return true;
     }
    

    //--------------------------------------------------------------------------------------------------
    private slots : bool onKeyRelease(QKeyEvent * event) { // returns true if need to call standard event handler

      if (event->key() == Qt::Key_Space) {
    
       emit spaceBarReleased();
       return false;
      }
    
      return true;
     }@
    

    But I'm facing with the problem: @obj->children();@ always reterns empty list, even when this object has child objects. So now I replace this by: @obj->inherits("QWidgetWindow");@ . It works, but it wrong, cause I can have more then two-level parent-child relation.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.