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. Creating and showing new QML objects from C++
Forum Updated to NodeBB v4.3 + New Features

Creating and showing new QML objects from C++

Scheduled Pinned Locked Moved QML and Qt Quick
qmlc++qobjecttext
2 Posts 2 Posters 1.3k Views 2 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.
  • J Offline
    J Offline
    JackCWallace
    wrote on last edited by JackCWallace
    #1

    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.

    p3c0P 1 Reply Last reply
    0
    • J JackCWallace

      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.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @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.

      157

      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