I changed the code
But I do not see any record in the TableView.
main.qml:
Qt Code:
  1. TableView {
  2. id: tablemodel
  3. anchors.fill: parent
  4. TableViewColumn {
  5. role: "col1"
  6. title: " "
  7. width: 30
  8. }
  9. model: myXML.newDataList
  10. // model: ListModel {
  11. // id: myModel
  12. // }
  13. }
To copy to clipboard, switch view to plain text mode 
myxml.h:
Qt Code:
  1. class MyXML: public QObject
  2. {
  3. Q_OBJECT
  4. //...
  5. Q_PROPERTY(QList<QObject*> newDataList READ getDataList WRITE setDataList NOTIFY dataListChanged)
  6. public:
  7. MyXML();
  8. MyXML(QString);
  9. //...
  10. Q_INVOKABLE QList<QObject*> getDataList() const;
  11. public slots:
  12. //...
  13. void setDataList(QList<QObject*> dataList);
  14. void saveXMLFile();
  15. void readXMLFile();
  16.  
  17. signals:
  18. //...
  19. void dataListChanged(QList<QObject*>);
  20. private:
  21. //...
  22. QList<QObject*> newDataList;
  23. };
To copy to clipboard, switch view to plain text mode 
myxml.cpp:
Qt Code:
  1. void MyXML::readXMLFile()
  2. {
  3. //...
  4. while(!reader.atEnd()) {
  5. reader.readNext();
  6. if (reader.isStartElement()) {
  7. //...
  8. if (reader.name() == "record") {
  9. foreach(const QXmlStreamAttribute &attr, reader.attributes()){
  10. newDataList.append(new DataObject("col1", attr.value().toString()));
  11. }
  12. }
  13. }
  14. }
  15. }
  16. void MyXML::saveXMLFile()
  17. {
  18.  
  19. }
To copy to clipboard, switch view to plain text mode 
I must write and open a XML file Like this:
Qt Code:
  1. <?xml version="1.0" standalone="yes"?>
  2. <NewDataSet>
  3. <record prop1=".." prop10="..." />
  4. .......
  5. <record prop1=".." prop10="..."/>
  6. </NewDataSet>
To copy to clipboard, switch view to plain text mode 
dataobject.h:
Qt Code:
  1. class DataObject:public QObject
  2. {
  3. Q_OBJECT
  4. Q_PROPERTY(QString newName READ name WRITE setName NOTIFY nameChanged)
  5. Q_PROPERTY(QString newValue READ value WRITE setValue NOTIFY ValueChanged)
  6. public:
  7. DataObject();
  8. DataObject(QString,QString);
  9. Q_INVOKABLE QString name() const;
  10. Q_INVOKABLE QString value() const;
  11. public slots:
  12. void setName(QString name);
  13. void setValue(QString value);
  14. signals:
  15. void nameChanged(QString);
  16. void valueChanged(QString);
  17. private:
  18. QString newName;
  19. QString newValue;
  20. };
To copy to clipboard, switch view to plain text mode 
dataobject.cpp:
Qt Code:
  1. #include "dataobject.h"
  2. DataObject::DataObject()
  3. {
  4. }
  5. DataObject::DataObject(QString name,QString value)
  6. {
  7. newName=name;
  8. newValue=value;
  9. }
  10. QString DataObject::name() const
  11. {
  12. return newName;
  13. }
  14. void DataObject::setName(QString name)
  15. {
  16. if (name != newName)
  17. {
  18. newName =name;
  19. emit nameChanged(newName);
  20. }
  21. }
  22. QString DataObject::value() const
  23. {
  24. return newValue;
  25. }
  26. void DataObject::setValue(QString value)
  27. {
  28. if (value!= newValue)
  29. {
  30. newValue = value;
  31. emit valueChanged(newValue);
  32. }
  33. }
To copy to clipboard, switch view to plain text mode