[Interest] QML Grid's children and findChild doesn't work

Igor Mironchik igor.mironchik at gmail.com
Mon Apr 11 17:49:33 CEST 2016


I have chess board defined in QML as:

  Grid {
         id: grid
         rows: 8
         columns: 8
         x: offset
         y: top.y + top.height
         objectName: "grid"

         Repeater {
             model: chessBoard

             delegate: Cell {
                 cellColor: model.CurrentPieceColor
                 chessX: index % 8
                 chessY: index / 8
                 onClicked: board.clicked( x, y )
                 onHovered: board.hovered( x, y )
                 objectName: "c"+ chessX + chessY
                 width: cellWidth
                 height: cellHeight
                 source: model.CellImageSource

So cell's objectName is something like c00, c01...

In C++ I have

QObject * cell = m_grid->findChild< QObject* > ( "c00" );

But it always return 0 with any cell's name. m_grid is the "grid" object...

Am I doing something wrong or this is a bug?

Thank you.

More information about the Interest mailing list