Results 1 to 5 of 5

Thread: ContextProperty of QQmlPropertyMap object is not writable at qml

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2025
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Post ContextProperty of QQmlPropertyMap object is not writable at qml

    Hello
    I have a conventional QQmlPropertyMap of contextproeprty working pretty well at qml ( is being read pretty well )
    but at the qml side I am not able to write any new value to it . what could be the reason of making QQmlPropertyMap object is not writable at qml side ?

    here is the C++ code side:

    Qt Code:
    1. QQmlPropertyMap* gDataProp;
    2. int main(int argc, char *argv[])
    3. {
    4. set_qt_environment();
    5. QGuiApplication app(argc, argv);
    6. ControlObjTreeModel uiObjectTreeMod;
    7. gDataProp =new QQmlPropertyMap();
    8. gDataProp->insert(mapNumOfSchObj,0);
    9. QJsonObject paramObj ={{shcObjName,"K0"} };
    10. QJsonObject paramIns[3];
    11. QJsonObject paramOut[2];
    12.  
    13. paramIns[0]={{ portName,"IN0"} , { portID,1}};
    14. paramIns[1]={{ portName,"IN1"} , { portID,2}};
    15. paramIns[2]={{ portName,"IN2"} , { portID,3}};
    16.  
    17. paramOut[0]={{ portName,"Out0"} , { portID,1}};
    18. paramOut[1]={{ portName,"Out1"} , { portID,2}};
    19.  
    20. GroupObject gIns [3];
    21. GroupObject gOuts [2];
    22.  
    23. qDebug() <<paramObj;
    24.  
    25. knx1 =new InterfaceObject(gDataProp,&paramObj ,paramIns, paramOut, gIns,gOuts ,3,2);
    26. paramObj[shcObjName]="Sw";
    27. sw1 =new InterfaceObject(gDataProp,&paramObj ,paramIns, paramOut, gIns,gOuts ,3,2);
    28.  
    29. QQmlApplicationEngine engine;
    30. const QUrl url(u"qrc:/qt/qml/Main/main.qml"_qs);
    31.  
    32. QObject::connect(
    33. &engine,
    34. &QQmlApplicationEngine::objectCreated,
    35. &app,
    36. [url](QObject *obj, const QUrl &objUrl) {
    37. if (!obj && url == objUrl)
    38. QCoreApplication::exit(-1);
    39. },
    40. Qt::QueuedConnection);
    41.  
    42. // BOLDFACE by OP for emphasis (Mod.)
    43. engine.rootContext()->setContextProperty("gDatPr", gDataProp );
    44. //
    45.  
    46. engine.addImportPath(QCoreApplication::applicationDirPath() + "/qml");
    47. engine.addImportPath(":/");
    48. engine.load(url);
    49.  
    50. if (engine.rootObjects().isEmpty()) {
    51. return -1;
    52. }
    53.  
    54. return app.exec();
    55. }
    56.  
    57. InterfaceObject:: InterfaceObject(QQmlPropertyMap * dmap ,QJsonObject* objParams
    58. , QJsonObject* insParam , QJsonObject* outsParam,
    59. GroupObject *inGo ,GroupObject *outGo, uint16_t numIns , uint16_t numOuts)
    60. :QObject (dmap)
    61. {
    62. int numOfSchObj ;
    63. schDataMap= dmap;
    64. interfaceData= new QJsonObject (*objParams);
    65. numOfIns=numIns;
    66. numOfOuts=numOuts;
    67. qDebug()<<*interfaceData;
    68.  
    69. numOfSchObj =schDataMap->value(mapNumOfSchObj).toInt();
    70. interfaceData->insert(shcObjID,numOfSchObj+1);
    71.  
    72. ins = new InterfacePort*[numIns];
    73. outs = new InterfacePort*[numOuts];
    74.  
    75. for (uint16_t i=0;i<numIns;i++)
    76. {
    77. ins [i]=new InterfacePort(insParam[i], inGo[i]);
    78. jsonArrayIn.push_back(ins [i]->getPortObj());
    79. }
    80.  
    81. interfaceData->insert(shcObjIns,jsonArrayIn);
    82. interfaceData->insert(shcObjNumOfIns,numOfIns);
    83. qDebug()<<*interfaceData;
    84.  
    85. for (uint16_t i=0;i<numOuts;i++)
    86. {
    87. outsParam[i].insert(pConnectionTarObjID,-2);
    88. outsParam[i].insert(pConnectionTarPortID,-4);
    89. outs [i]=new InterfacePort(outsParam[i], outGo[i]);
    90. jsonArrayIn2.push_back(outs[i]->getPortObj());
    91. }
    92.  
    93. interfaceData->insert(shcObjOuts,jsonArrayIn2);
    94. interfaceData->insert(shcObjNumOfOuts,numOfOuts);
    95.  
    96. objKey=new QString (mapSchObjHeader + QString::number(numOfSchObj));
    97. schDataMap->insert(*objKey , *interfaceData);
    98.  
    99. // BOLDFACE by OP for emphasis (Mod.)
    100. schDataMap->insert( mapNumOfSchObj ,numOfSchObj+1);
    101.  
    102.  
    103. schDataMap->connect(
    104. schDataMap,
    105. &QQmlPropertyMap::valueChanged,
    106. this,
    107. &InterfaceObject::updateFromGuiSlot);
    108. // end boldface
    109.  
    110. }
    To copy to clipboard, switch view to plain text mode 
    and in qml Side:
    gDatPr["SO0"] [api.shcObjName]="newName"
    console.log( "test Name ",gDatPr["SO0"] [api.shcObjName])



    console.log is still showing the old name "K0"


    *** Moderator's note: inserted CODE tags for readability. I apologize that embedded boldface font is not supported in CODE sections. Hopefully my added comments will help.
    Last edited by d_stranz; 26th January 2025 at 17:52. Reason: missing [code] tags

Similar Threads

  1. Replies: 1
    Last Post: 13th December 2018, 18:24
  2. TypeError: Object [object Object] has no method 'sendData'
    By TheIndependentAquarius in forum Qt Quick
    Replies: 2
    Last Post: 30th November 2013, 06:54
  3. QQmlPropertyMap, model
    By sBoff in forum Qt Quick
    Replies: 7
    Last Post: 27th August 2013, 11:33
  4. Replies: 3
    Last Post: 11th July 2012, 13:40
  5. Replies: 1
    Last Post: 8th November 2011, 23:27

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
  •  
Qt is a trademark of The Qt Company.