Creating and showing new QML objects from C++



  • Hi, I am trying to create a new object in C++, and delete an old one, basically replacing it. I have created the QObject, and have given it the properties I want, but I cannot show it on the page.

            QObject *j = new QObject();                
    
            j->setParent(title->parent());
            j->setProperty("x", title->property("x"));
            j->setProperty("y", title->property("y"));
            j->setProperty("z", title->property("z"));
            j->setProperty("width", title->property("width"));
            j->setProperty("height", title->property("height"));
            j->setProperty("color", "#ffffff");
            j->setProperty("text", val.trimmed());
    
            title->setProperty("text",val.trimmed());
    

    basically I want to create j, and replace title with it.

    I understand I can change the text of title, but that is not what I want to do.


  • Moderators

    @JackCWallace You need to set an visual parent to the newly created item using setParentItem. For this you will have to create a QQuickItem ofcourse.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.