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


so change property of qml object via c++ code, couldn't see result on screen. have item repeated 64 times, , want image displayed 32nd item (from c++) used invokemethod access object via c++ used setproperty change visibility, if view qdebug property "visible" did change, notice no difference on screen still cannot see image, if change visibility qml, can see it.

this 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 verify property changed

this 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"                 }             }         }     }   } 

qquickview , qqmlapplicationengine alternative ways load , show qml views. loading qqmlapplicationengine has nothing visible output of qquickview.

in order things running, need change top element of qml file item window , show on screen:

qqmlapplicationengine engine; engine.load(qurl(qstringliteral("qrc:///board.qml"))); // end of code  qobject *rootobject = engine.rootobjects().first(); qquickwindow *window = qobject_cast<qquickwindow *>(rootobject); if (!window) {     qdebug() << "error: root item has window.";     return -1; } window->show();  // continue code qquickitem *qmlobject = rootobject->findchild<qquickitem*>("grid")->findchild<qquickitem*>("repeter"); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -