QML object property changed from c++, but I can't see the result

Reda Drissi

So I could change the property of a certain QML object via C++ code, but I couldn't see the result on screen. I have an item repeated 64 times, and I want a certain image to be displayed only for the 32nd item (from C++) so I used invokeMethod to access the object via C++ then I used setProperty to change the visibility, if I view it with qDebug the property "visible" did change, but I notice no difference on the screen I still cannot see the image, but if I change the visibility from qml, I can see it.

This is the C++ code:

int main(int argc, char *argv[])
{
  QGuiApplication app(argc, argv);
  QQuickView view;
  view.setSource(QUrl("qrc:///main.qml"));
  view.show();
  QQuickItem* child;
  QQmlApplicationEngine engine;
  engine.load(QUrl(QStringLiteral("qrc:///Board.qml")));
  QObject *rootObject = engine.rootObjects().first();
  QQuickItem *qmlObject = rootObject->findChild<QQuickItem*>("grid")->findChild<QQuickItem*>("repeter");
  QMetaObject::invokeMethod(qmlObject,"itemAt",Qt::DirectConnection,   Q_RETURN_ARG (QQuickItem*,child), Q_ARG(int,32));
  child=child->findChild<QQuickItem*>("pleaseWork");
  qDebug() << child->property("visible");
  child->setProperty("visible","true");
  qDebug() << child->property("visible");
  return app.exec();
}

I used qDebug to verify the property changed

This is the QML code :

Item 
{
    id: root
    width: 8*45
    height: 8*45
    Grid 
    {
        id: grid
        objectName: "grid"
        rows: 8
        Repeater 
        {
            objectName: "repeter"
            model: 64 
            Image
            {
                objectName: "test"
                width: 45; height: 45 
                source: "images/dark_square.png"
                Image
                {
                    id: isit
                    objectName: "pleaseWork"
                    visible: false
                    source: "images/avail_dark.png"
                }
            }
        }
    }  
}
Simon Warta

QQuickView and QQmlApplicationEngine are alternative ways to load and show QML views. What you are loading into QQmlApplicationEngine has nothing to do with the visible output of QQuickView.

In order to get things running, you need to change the top element of the QML file from Item to Window and show it on screen:

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///Board.qml")));
// end of your code

QObject *rootObject = engine.rootObjects().first();
QQuickWindow *window = qobject_cast<QQuickWindow *>(rootObject);
if (!window) {
    qDebug() << "Error: Your root item has to be a window.";
    return -1;
}
window->show();

// continue with your code
QQuickItem *qmlObject = rootObject->findChild<QQuickItem*>("grid")->findChild<QQuickItem*>("repeter");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

QML object property changed from c++, but I can't see the result

From Dev

Can't see the property of a object in nodejs

From Dev

Can't get changed property from attachPropertyChange

From Dev

How can I determine if a property in an object has changed

From Dev

Why can´t I see complete name in SSMS result list?

From Dev

Why can´t I see complete name in SSMS result list?

From Dev

How do I notify the container object that a property has changed from the object being changed?

From Dev

How do I notify the container object that a property has changed from the object being changed?

From Dev

Setting object type property in QML from C++

From Dev

Why can't I see all stats for object from Facebook Graph API

From Dev

Why can't I set this object property?

From Dev

xCode - Why can't I see this object on the view?

From Dev

Compiler says object is const, I can't see how

From Dev

Why can't I see the keys of an Error object?

From Dev

xCode - Why can't I see this object on the view?

From Dev

How can I pass a QML object reference into Qt C++?

From Dev

I can't see changed files on "commit changes" screen in Android Studio

From Dev

Can I see object sent from ajax to php in php with a debugger?

From Dev

Prevent QML Property Bindings when QML object isn't visible?

From Dev

Can't see the expected result in a jQuery lab

From Dev

Can't access C++ QObject subclass methods from QML

From Dev

C# - pass object with property changed

From Dev

How can I listen to a C++ signal from QML?

From Dev

Why can I not use KVC from an Objective-C object to a Swift Property?

From Dev

(C# - WPF) I can`t see labels and other elements

From Dev

(C# - WPF) I can`t see labels and other elements

From Dev

mongoose find result can't use as an object when I loop it

From Dev

How can I use a destructor in C++ when an object can be changed in another object

From Dev

I can't access the properties of an object even though I can see it's contents

Related Related

  1. 1

    QML object property changed from c++, but I can't see the result

  2. 2

    Can't see the property of a object in nodejs

  3. 3

    Can't get changed property from attachPropertyChange

  4. 4

    How can I determine if a property in an object has changed

  5. 5

    Why can´t I see complete name in SSMS result list?

  6. 6

    Why can´t I see complete name in SSMS result list?

  7. 7

    How do I notify the container object that a property has changed from the object being changed?

  8. 8

    How do I notify the container object that a property has changed from the object being changed?

  9. 9

    Setting object type property in QML from C++

  10. 10

    Why can't I see all stats for object from Facebook Graph API

  11. 11

    Why can't I set this object property?

  12. 12

    xCode - Why can't I see this object on the view?

  13. 13

    Compiler says object is const, I can't see how

  14. 14

    Why can't I see the keys of an Error object?

  15. 15

    xCode - Why can't I see this object on the view?

  16. 16

    How can I pass a QML object reference into Qt C++?

  17. 17

    I can't see changed files on "commit changes" screen in Android Studio

  18. 18

    Can I see object sent from ajax to php in php with a debugger?

  19. 19

    Prevent QML Property Bindings when QML object isn't visible?

  20. 20

    Can't see the expected result in a jQuery lab

  21. 21

    Can't access C++ QObject subclass methods from QML

  22. 22

    C# - pass object with property changed

  23. 23

    How can I listen to a C++ signal from QML?

  24. 24

    Why can I not use KVC from an Objective-C object to a Swift Property?

  25. 25

    (C# - WPF) I can`t see labels and other elements

  26. 26

    (C# - WPF) I can`t see labels and other elements

  27. 27

    mongoose find result can't use as an object when I loop it

  28. 28

    How can I use a destructor in C++ when an object can be changed in another object

  29. 29

    I can't access the properties of an object even though I can see it's contents

HotTag

Archive