Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qml inspection, eventFilter
Forum Updated to NodeBB v4.3 + New Features

Qml inspection, eventFilter

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlc++
2 Posts 2 Posters 321 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.
  • C Offline
    C Offline
    Chruetli
    wrote on last edited by
    #1

    I want to build a documentation lookup/help system for my Qml interface elements. My interface has different "active" items like buttons, input fileds and "inactive" items like labels.
    My idea is to give every ui element an doc-Id as property (or function return value) which acts as document lookup value.
    The idea is to switch to a help mode and activate my event filter. The event filter should filter mouse-clicks and find the doc-Id of the clicked item.
    I was able to implement a cusomized event-filter but when I dump the source object I cannot see my component nor get the property...

      virtual bool eventFilter(QObject *watched, QEvent *event) override {
        if (event->type() == QEvent::Type::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) {
          qDebug() << __FUNCTION__ << ":" << watched << watched->property("docId") << " - " << event->type();
    //      auto count = watched->metaObject()->propertyCount();
    //      for (int i = 0; i<count; ++i) {
    //        qDebug()  << QString::fromUtf8(watched->metaObject()->property(i).name());
    //      }
    //      QMetaObject::invokeMethod(watched, "getDocId");
        }
            return QObject::eventFilter(watched, event);
      }
    
    

    Better ideas

    1 Reply Last reply
    1
    • KH-219DesignK Offline
      KH-219DesignK Offline
      KH-219Design
      wrote on last edited by
      #2

      I'll check back tomorrow or Tuesday to see if I can better explain the code that I am about to share.

      I'm in a hurry today, so I'm just going to paste this and hope that anyone reading it can make use of it :)

      #include <QQmlComponent>
      #include <QQmlProperty>
      #include <QQuickItem>
      
      
      void dumpRecursive( int level, QObject* object )
      {
          if( object )
          {
              QByteArray buf;
              buf.fill( ' ', level / 2 * 8 );
              if( level % 2 )
                  buf += "    ";
      
              QString name = object->objectName();
      
              QVariant propv = QQmlProperty::read( object, "visible" );
              if( propv.isNull() )
              {
                  fprintf( stderr, "%s\n", "IS_NULL visible prop" );
              }
              else
              {
                  QQmlProperty prop( object, "visible" );
                  fprintf( stderr, "hasNotifySignal %d\n",
                      static_cast<int>( prop.hasNotifySignal() ) );
                  fprintf( stderr, "isResettable %d\n",
                      static_cast<int>( prop.isResettable() ) );
                  fprintf( stderr, "isSignalProperty %d\n",
                      static_cast<int>( prop.isSignalProperty() ) );
                  fprintf( stderr, "isValid %d\n", static_cast<int>( prop.isValid() ) );
                  fprintf( stderr, "isWritable %d\n", static_cast<int>( prop.isWritable() ) );
                  fprintf( stderr, "propertyTypeName %s\n", prop.propertyTypeName() );
                  fprintf( stderr, "needsNotifySignal %d\n",
                      static_cast<int>( prop.needsNotifySignal() ) );
      
                  // bool QQmlProperty::needsNotifySignal() const
                  // QMetaMethod m = prop.method();
              }
      
              QVariant prop = QQmlProperty::read( object, "testtest" );
              if( !prop.isNull() )
              {
                  if( !prop.canConvert<QList<QVariant>>() )
                  {
                      fprintf( stderr, "%s\n", "whoooooooooooooooooooooooooops ! ! !" );
                  }
                  else
                  {
                      QList<QVariant> list = prop.toList();
                      fprintf( stderr, "wheeeeeeeeeeeeeeeee %p\n", reinterpret_cast<void*>( &list ) );
                      for( const auto& state : list )
                      {
                          fprintf( stderr, "got one %p\n", reinterpret_cast<void*>( &list ) );
                          if( state.canConvert<QQuickItem*>() )
                          {
                              QQuickItem* t = state.value<QQuickItem*>();
                              fprintf( stderr, "converts one %p\n", reinterpret_cast<void*>( t ) );
                          }
                      }
                  }
              }
      
              qDebug( "%s%s::%s", reinterpret_cast<const char*>( buf.data() ), object->metaObject()->className(),
                  name.toLocal8Bit().data() );
      
              QObjectList children = object->children();
              if( !children.isEmpty() )
              {
                  for( int i = 0; i < children.size(); ++i )
                      dumpRecursive( level + 1, children.at( i ) );
              }
          }
      }
      
      void localDump( QObject* object )
      {
          dumpRecursive( 0, object );
      }
      
      
      // return true if the event should be filtered (i.e. stopped)
      bool EventFilter::eventFilter( QObject* obj, QEvent* event )
      {
      
          localDump( obj );
      
          return QObject::eventFilter( obj, event );
      }
      

      www.219design.com
      Software | Electrical | Mechanical | Product Design

      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