Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QObject method children returns empty list.
Forum Updated to NodeBB v4.3 + New Features

QObject method children returns empty list.

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 915 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anticross
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved