Results 1 to 3 of 3

Thread: Weird metaObject->className extension for QML "ghost"-items

  1. #1
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Weird metaObject->className extension for QML "ghost"-items

    Hi,
    I am trying to implement a simple collision detection. I am experiencing some strange behaviour with items that should not exist and are not visible (while invisibly having a location on the screen, see below) - but are found while iterating through QQuickWindow::contentItem's childItems.

    I do find the expected Items:
    CustomButton_QMLTYPE_17
    Ok, that looks reasonable.
    The unexpected Items go by this name:
    CustomButton_QMLTYPE_17_QML_34
    Where does the _QML_34 come from? Are they "invalid"/"old" in any way, just not yet deleted by QML?

    I should add, that both numbers (here 17/34) change every time I run the program, (e.g. 67/72, 63/68, 45/62). The numbers seem to be somewhat random, the latter being always higher than the first. While the program is running, they stay constant.

    For my view I am using a c++-model-driven QML Repeater which uses a rather complex "CustomButton.qml" as a delegate. Those CustomButtons are built from my own "CollidingItem" class, which inherits from QQuickItem. Works well.
    collidingquickitem.h:
    Qt Code:
    1. class CollidingQuickItem: public QQuickItem
    2. {
    3. Q_OBJECT
    4. public:
    5. CollidingQuickItem();
    6. ...
    To copy to clipboard, switch view to plain text mode 
    CustomButton.qml:
    Qt Code:
    1. CollidingQuickItem {
    2. id: personButtonBasis
    3. objectName: "unknownCustomButton"
    4. x: 0
    5. y: 0
    6. width: 100
    7. height: 100
    8. ....
    To copy to clipboard, switch view to plain text mode 
    ClassroomScene.qml:
    Qt Code:
    1. ...
    2. Repeater {
    3. id: personRepeater
    4. model: groupContent.personButtonContents
    5. delegate: CustomButton {
    6. id: customButtonDelegate
    7. objectName: personRepeater.model[index].nameTop+" "+personRepeater.model[index].nameBottom
    8. ...
    9. x: personRepeater.model[index].position.x
    10. y: personRepeater.model[index].position.y
    11. height: 90
    12. width: 90
    13. ...
    14. }
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    To find collisions I am crawling through the childItems of QQuickWindow::contentItem, to find all "CollidingQuickItem"-Items, yet without actual collision testing. After this, the resultList contains both expected and unexpected items:
    Qt Code:
    1. QList<QQuickItem *> Controller::findAllCollidingChildItemsRecursively(QQuickItem *item)
    2. {
    3. QList<QQuickItem*> resultList;
    4. if (!item) {
    5. return resultList;
    6. }
    7. bool isCollider=(dynamic_cast<CollidingQuickItem*>(item));
    8. if ((isCollider)&&(!resultList.contains(item))) {
    9. resultList.append(item);
    10. //no further checking
    11. } else {
    12. foreach (QQuickItem* childItem, item->childItems()) {
    13. resultList.append(findAllCollidingChildItemsRecursively(childItem));
    14. }
    15. }
    16. return resultList;
    17. }
    To copy to clipboard, switch view to plain text mode 

    The actual collisionCheck reveals the strange "ghost"-Items that I've never (willingly) instantiated, mainly in the upper left of the screen:
    Qt Code:
    1. QList<QQuickItem *> Controller::itemsCollidingWith(QRectF rect)
    2. {
    3. QList<QQuickItem *> resultList;
    4. QQuickWindow* w = this->topLevelWindow();
    5. foreach (QQuickItem* i, findAllCollidingChildItemsRecursively(w->contentItem())) {
    6. if (rect.intersects(QRectF(i->x(),i->y(),i->width(),i->height()))) {
    7. resultList.append(i);
    8. qDebug()<<"Detection for "<<i->objectName()<<" / "<<i->metaObject()->className();
    9. qDebug()<<typeid(i).name();
    10. }
    11.  
    12. }
    13. return resultList;
    14. }
    To copy to clipboard, switch view to plain text mode 

    Interestingly, the typeId is always the same, the className differs between those items that are visible and should be there - and the others.
    Normal output (hitting a visible item):
    Detection for "Carsten Ernst" / CustomButton_QMLTYPE_17
    P10QQuickItem
    Unexpected output (testing an empty area on the top / topLeft of the screen):
    "unknownCustomButton" / CustomButton_QMLTYPE_17_QML_34
    P10QQuickItem
    There are several of these "unknownCustomButton"s.

    Any information about QML's className generation or a possible origin of those items would be cool.
    Last edited by sedi; 13th September 2015 at 15:20.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Weird metaObject->className extension for QML "ghost"-items

    Do you have any local properties in the delegate?
    I.e. something that would require the QML engine to create a new type for each delegate instance.

    Btw, model data is usually accessed directly through "model.propertyName" or "modelData" (depending on whether this is an actual model or a list of values.

    Also, while not answering your question, one thing you could do it to let the CollidingQuickItem constructor register the instance at some global/singleton object and the destructor unregistring.
    That way you would never have to search for them.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    sedi (13th September 2015)

  4. #3
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Weird metaObject->className extension for QML "ghost"-items

    Thank you, anda_skoa, for your answer!

    While playing around with the ideas I took from your post, I have actually found the somewhat embarrassing reason for the "ghost" items - in Layer 8...

    There are some instances of a qml subclass of those CustomButtons, that live within another item's area. Thus their positions are relative to that item - not relative to the screen. I have checked collisions with their verbatim x and y values, subsequently getting "hits" in the upper left area of the screen (where they are not located - their parent item lives at the screen's bottom). So I thought I'd hit a "ghost", which I didn't.

    Given this, the _QML_*-Extension obviously reflects being a qml subclass of the _QMLTYPE_*.

    The idea to register the instances from the constructor of CollidingQuickItem is cool! As my collision checking is on user interaction only, it is time-uncritical and I favour the crawling over the bookkeeping. In other situations, though, I'll definitely heed that advice!

    Thank you very much for your time!

Similar Threads

  1. Replies: 1
    Last Post: 2nd September 2014, 10:19
  2. Replies: 0
    Last Post: 15th April 2011, 20:04
  3. xlib: extension "XFree86-DRI" missing on display ":0.0".
    By kiransu123 in forum Qt Programming
    Replies: 5
    Last Post: 3rd August 2009, 15:43
  4. Replies: 0
    Last Post: 3rd December 2008, 12:58
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.