Results 1 to 10 of 10

Thread: Display data from XML file in TableView

  1. #1
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default Display data from XML file in TableView

    Hi,
    I want to display data in TableView which I am getting from XML file.
    I wrote this code, but I have some error like this:
    'QObject::QObject' : cannot access private member declared in class 'QObject' => error of dataobject.h
    my code is correct?
    main.cpp:
    Qt Code:
    1. MyModel mymodel;
    2. engine.rootContext()->setContextProperty("mymodel", &mymodel);
    To copy to clipboard, switch view to plain text mode 

    main.qml:
    Qt Code:
    1. TableView {
    2. id: tablemodel
    3. MyTableViewColumn {
    4. role: "pro1"
    5. title: "pro1"
    6. width: 70
    7. }
    8. ...
    9. ...
    10. MyTableViewColumn {
    11. role: "pro11"
    12. title: "pro11"
    13. width: 60
    14. }
    15. MyTableViewColumn {
    16. role: "index"
    17. title: " "
    18. width: 30
    19. }
    20. model: ListModel {
    21. id: myModel
    22. source:myModel.mydata
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

    dataobject.h:
    Qt Code:
    1. #ifndef DATAOBJECT_H
    2. #define DATAOBJECT_H
    3. #include <QObject>
    4. class DataObject: public QObject
    5. {
    6. Q_OBJECT
    7. Q_PROPERTY(QString newIndex READ getIndex WRITE setIndex NOTIFY indexChanged)
    8. Q_PROPERTY(QString newpro1 READ getpro1 WRITE setpro1 NOTIFY pro1Changed)
    9. ...
    10. ...
    11. Q_PROPERTY(QString newpro11 READ getpro11 WRITE setpro11 NOTIFY pro11Changed)
    12. Q_PROPERTY(QByteArray newImage READ getImage WRITE setImage NOTIFY imageChanged)
    13.  
    14.  
    15. public:
    16. DataObject();
    17.  
    18. Q_INVOKABLE QString getIndex() const;
    19. Q_INVOKABLE QString getpro1() const;
    20. ...
    21. ...
    22. Q_INVOKABLE QString getpro11() const;
    23. Q_INVOKABLE QByteArray getImage() const;
    24.  
    25. public slots:
    26.  
    27. void setIndex(QString index);
    28. void setpro1(QString pro1);
    29. ..
    30. ...
    31. void setpro11(QString pro11);
    32. void setImage(QByteArray image);
    33.  
    34. signals:
    35. void indexChanged(QString);
    36. void pro1Changed(QString);
    37. ...
    38. ...
    39. void pro11Changed(QString);
    40. void imageChanged(QByteArray);
    41.  
    42. private:
    43.  
    44. QString newIndex;
    45. QString newpro1;
    46. ...
    47. ...
    48. QString newpro11
    49. QByteArray newImage;
    50. };
    51.  
    52. #endif // DATAOBJECT_H
    To copy to clipboard, switch view to plain text mode 

    dataobject.cpp:
    Qt Code:
    1. #include "dataobject.h"
    2.  
    3. DataObject::DataObject()
    4. {
    5. }
    6. DataObject::DataObject(QString index,QString pro1,.......,QString pro11)
    7. {
    8. newpro1=pro1;
    9. ...
    10. ...
    11. newpro11=pro11;
    12. }
    13.  
    14. QString DataObject::getpro1() const
    15. {
    16. return newpro1;
    17. }
    18. void DataObject::setpro1(QString pro1)
    19. {
    20. if (pro1 != newpro1)
    21. {
    22. newpro1= pro1;
    23. emit pro11Changed(pro1);
    24. }
    25. }
    26.  
    27. ...
    28. ...
    29.  
    30. QString DataObject::getpro11() const
    31. {
    32. return newpro11;
    33. }
    34. void DataObject::setpro11(QString pro11)
    35. {
    36. if (pro11 != newpro11)
    37. {
    38. newpro11= pro11;
    39. emit pro11Changed(pro11);
    40. }
    41. }
    42.  
    43. QByteArray DataObject::getImage() const
    44. {
    45. return newImage;
    46. }
    47. void DataObject::setImage(QByteArray image)
    48. {
    49. if (image != newImage)
    50. {
    51. newImage= image;
    52. emit imageChanged(image);
    53. }
    54. }
    To copy to clipboard, switch view to plain text mode 

    mymodel.h:
    Qt Code:
    1. #ifndef MYMODEL_H
    2. #define MYMODEL_H
    3.  
    4. #include <QAbstractListModel>
    5. #include <dataobject.h>
    6.  
    7. class MyModel : public QAbstractTableModel
    8. {
    9. Q_OBJECT
    10. std::vector<DataObject> mydata;
    11. public:
    12. typedef std::vector<DataObject>::const_iterator const_iterator;
    13. explicit MyModel(QObject *parent = 0);
    14. enum {index,hardness,fromFirst,avgDiam,omgheAsar,firstDiam,secondDiam,timeNiro,niro,method,zoom,MAX_COLS};
    15.  
    16. int rowCount(const QModelIndex &parent) const;
    17. int columnCount(const QModelIndex &parent) const;
    18. QVariant data(const QModelIndex &index, int role) const;
    19. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
    20. void addData(DataObject data);
    21. void removeData(int row);
    22. bool setData(const QModelIndex &index, const QVariant &value, int role);
    23. Qt::ItemFlags flags(const QModelIndex &index) const;
    24. DataObject& getData(size_t index);
    25. const_iterator begin()const{return mydata.begin();}
    26. const_iterator end()const{return mydata.end();}
    27. };
    28.  
    29.  
    30. #endif // MYMODEL_H
    To copy to clipboard, switch view to plain text mode 

    mymodel.cpp

    Qt Code:
    1. #include "mymodel.h"
    2.  
    3. QVariant MyModel::data(const QModelIndex &index, int role) const
    4. {
    5. if(!index.isValid())
    6. return QVariant();
    7.  
    8. if(index.row() >= mydata.size() || index.row() < 0)
    9. return QVariant();
    10.  
    11. if(role == Qt::DisplayRole || role == Qt::EditRole)
    12. {
    13. switch(index.column())
    14. {
    15. case prop1:
    16. return mydata[index.row()].getprop1();
    17. ...
    18. ...
    19. case prop11:
    20. return mydata[index.row()].getprop11();
    21. }
    22. }
    23. return QVariant();
    24. }
    25. QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const
    26. {
    27. if(role != Qt::DisplayRole)
    28. return QVariant();
    29.  
    30. if (orientation == Qt::Horizontal)
    31. {
    32. switch (section)
    33. {
    34.  
    35. case 1:
    36. return tr("pro1");
    37. ...
    38. ...
    39. case 9:
    40. return tr("pro11");
    41. }
    42. }
    43. return QVariant();
    44. }
    45. bool MyModel::setData(const QModelIndex &index, const QVariant &value, int role)
    46. {
    47. if (index.isValid() && role == Qt::EditRole && !(index.row() >= mydata.size() || index.row() < 0))
    48. {
    49. int row = index.row();
    50.  
    51. switch(index.column())
    52. {
    53. case 0:
    54. mydata[row].setIndex(value.toString());
    55. break;
    56. case 1:
    57. mydata[row].setpro1(value.toString());
    58. break;
    59. ...
    60. ...
    61. case 11:
    62. mydata[row].setprop11(value.toString());
    63. break;
    64. default:
    65. return false;
    66. }
    67. emit dataChanged(index, index);
    68. return true;
    69. }
    70. return false;
    71. }
    72. Qt::ItemFlags MyModel::flags(const QModelIndex &index) const
    73. {
    74. if (!index.isValid())
    75. return Qt::ItemIsEnabled;
    76. return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
    77. }
    78. void MyModel::addData(DataObject data)
    79. {
    80. if(std::find(mydata.begin(),mydata.end(),data)!=mydata.end())
    81. return;
    82. beginInsertRows(QModelIndex(),mydata.size(),mydata.size());
    83. /*BOOST_SCOPE_EXIT(this_){
    84.   this_->endInsertRows();
    85.   }BOOST_SCOPE_EXIT_END*/
    86. mydata.push_back(std::move(data));
    87. endInsertRows();
    88. }
    89. void MyModel::removeData(int row)
    90. {
    91. beginRemoveRows(QModelIndex(),row,row);
    92. /*BOOST_SCOPE_EXIT(this_){
    93.   this_->endRemoveRows();
    94.   }BOOST_SCOPE_EXIT_END//*/
    95. mydata.erase(std::next(mydata.begin(),row));
    96. //endRemoveRows();
    97. }
    To copy to clipboard, switch view to plain text mode 

    myxml.xpp:
    Qt Code:
    1. void MyXML::saveXMLFile()
    2. {
    3. QFile file(newFileName);
    4. file.open(QIODevice::WriteOnly);
    5.  
    6. QXmlStreamWriter xmlWriter(&file);
    7. xmlWriter.setAutoFormatting(true);
    8. xmlWriter.writeStartDocument();
    9.  
    10. xmlWriter.writeStartElement("NewDataSet");
    11.  
    12. xmlWriter.writeStartElement("header");
    13. ...
    14. ...
    15. xmlWriter.writeEndElement();
    16.  
    17. MyModel model;
    18. MyModel::const_iterator it = model.begin(),end = model.end();
    19. for(;it != end;++it)
    20. {
    21. xmlWriter.writeStartElement("record");
    22.  
    23. // QFile fileImg(newImage);
    24. // fileImg.open(QIODevice::ReadOnly);
    25.  
    26. // QByteArray imageData = fileImg.readAll();
    27. // QByteArray imageData_Base64 = imageData.toBase64();
    28.  
    29. // xmlWriter.writeAttribute("image",imageData_Base64);
    30.  
    31. xmlWriter.writeTextElement("index",it->getIndex());
    32. xmlWriter.writeTextElement("prop1",it->getprop1());
    33. ...
    34. ...
    35. xmlWriter.writeTextElement("prop11",it->getprop11());
    36.  
    37. xmlWriter.writeEndElement();
    38. }
    39.  
    40. xmlWriter.writeEndElement();
    41.  
    42. file.close();
    43. }
    44.  
    45. void MyXML::readXMLFile()
    46. {
    47. QFile file(newFileName);
    48. if (!file.open(QFile::ReadOnly | QFile::Text))
    49. {
    50. //qDebug() << "Error: Cannot read file ";
    51. return;
    52. }
    53. QXmlStreamReader reader(file.readAll());
    54. file.close();
    55.  
    56. while(!reader.atEnd()) {
    57. reader.readNext();
    58. if (reader.isStartElement()) {
    59. if (reader.name() == "header") {
    60.  
    61. foreach(const QXmlStreamAttribute &attr, reader.attributes()) {
    62. ...
    63. ...
    64. }
    65. }
    66. else if (reader.name() == "recorde") {
    67.  
    68. QString prop1,...,prop11;
    69.  
    70. foreach(const QXmlStreamAttribute &attr, reader.attributes()){
    71. if(attr.name().toString() == QLatin1String("index")){
    72. index=attr.value().toString();
    73. }
    74. else if(attr.name().toString() == QLatin1String("prop1")){
    75. prop1=attr.value().toString();
    76. }
    77.  
    78. ...
    79. ...
    80.  
    81. else if(attr.name().toString() == QLatin1String("prop11")){
    82. prop11=attr.value().toString();
    83. }
    84.  
    85. }
    86. MyModel model;
    87. model.addData(DataObject(index,prop1,....,prop11));
    88. }
    89. }
    90. }
    91. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display data from XML file in TableView

    Here
    Qt Code:
    1. std::vector<DataObject> mydata;
    To copy to clipboard, switch view to plain text mode 
    you are using DataObject as a value type, meaning you are working with copies when adding to or reading from the vector.

    But DataObject is a QObject dervied class, instances of QObject cannot be copied.
    You don't need the model's data clas to be derived from QObject, it is never directly exposed to QML.

    Aside from that:
    - you need a list model not a table model, as QtQuick only works on list models
    - you need to overwrite the model's rolesNames() method to provide a mapping from QML role names to your role enum values.
    - your MyXML method will want to work on the model that you expose to QML, not on newly created instances that get deleted at the end of the method

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    neda (24th February 2016)

  4. #3
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Display data from XML file in TableView

    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 

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display data from XML file in TableView

    Quote Originally Posted by neda View Post
    I changed the code
    Any specific reason you did not just fix the model but went for a totally different approac

    Quote Originally Posted by neda View Post
    But I do not see any record in the TableView.
    I am not sure what you expect to see.
    You tell the TableViewColumn to use "col1" as the role, yet your data has no "col1", it has "newName" and "newValue".

    So, from your point of view, which of these tw comparions should be true?
    Qt Code:
    1. "col1" == "newName"
    2. "col1" == "newValue"
    To copy to clipboard, switch view to plain text mode 
    As far as I know neither C++ nor JavaScript would evaluate either of these two as true.

    Cheers,
    _

  6. #5
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Display data from XML file in TableView

    Thank you for your answer.

    Quote Originally Posted by anda_skoa View Post
    I am not sure what you expect to see.
    You tell the TableViewColumn to use "col1" as the role, yet your data has no "col1", it has "newName" and "newValue".

    _
    I have this XML file:
    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 

    And I have a TableView with this columns:
    prop1, .... , prop10

    I want to use newName for name of columns(name=prop1 , .. , prop10) and newValue for value of attributes in XML file.
    I do not see any record in tableview.

    Quote Originally Posted by anda_skoa View Post

    So, from your point of view, which of these tw comparions should be true?
    Qt Code:
    1. "col1" == "newName"
    2. "col1" == "newValue"
    To copy to clipboard, switch view to plain text mode 

    _
    Excuse me, you are right. I mistake to write code here. I put "newDataList.append(new DataObject("name of column ==for example prop1", attr.value().toString())); " for test.

    I can display my XML file using XmlListModel in Tableview, but I can not save all record of Tableview in XML file by using XmlListModel.
    I write another code by using QAbstractTableModel, but I do not see any data after open XML file in Tableview.

    If you are agree I want to put a another sample program by QAbstractTableModel.

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display data from XML file in TableView

    My recommendation is to re-read comment #2.

    Cheers,
    _

  8. #7
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Display data from XML file in TableView

    Quote Originally Posted by anda_skoa View Post
    Here
    Qt Code:
    1. std::vector<DataObject> mydata;
    To copy to clipboard, switch view to plain text mode 
    you are using DataObject as a value type, meaning you are working with copies when adding to or reading from the vector.

    But DataObject is a QObject dervied class, instances of QObject cannot be copied.
    You don't need the model's data clas to be derived from QObject, it is never directly exposed to QML.

    Aside from that:
    - you need a list model not a table model, as QtQuick only works on list models
    - you need to overwrite the model's rolesNames() method to provide a mapping from QML role names to your role enum values.
    - your MyXML method will want to work on the model that you expose to QML, not on newly created instances that get deleted at the end of the method

    _
    mymodel.h:
    Qt Code:
    1. #ifndef MYMODEL_H
    2. #define MYMODEL_H
    3.  
    4. #include <QStandardItemModel>
    5. class MyModel : public QStandardItemModel {
    6.  
    7. public:
    8. enum Role {
    9. role1=Qt::UserRole,
    10. role2,
    11. role3
    12. };
    13.  
    14. explicit MyModel(QObject * parent = 0): QStandardItemModel(parent){}
    15. explicit MyModel( int rows, int columns, QObject * parent = 0 )
    16. : QStandardItemModel(rows, columns, parent){}
    17.  
    18. QHash<int, QByteArray> roleNames() const{
    19. QHash<int, QByteArray> roles;
    20. roles[role1] = "one";
    21. roles[role2] = "two";
    22. roles[role3] = "three";
    23. return roles;
    24. }
    25. };
    26.  
    27.  
    28. #endif // MYMODEL_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MyXML::saveXMLFile()
    2. {
    3. ?????
    4. }
    5.  
    6.  
    7. void MyXML::readXMLFile()
    8. {
    9. MyModel model;
    10. foreach(const QXmlStreamAttribute &attr, reader.attributes()){
    11.  
    12. it->setData(attr.value().toString(), MyModel::role1);// Just for test
    13. it->setData(attr.value().toString(), MyModel::role2);// Just for test
    14. it->setData(attr.value().toString(), MyModel::role3);// Just for test
    15. model.appendRow(it);
    16. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp:
    Qt Code:
    1. MyModel* model = new MyModel;
    2.  
    3.  
    4. it->setData("data 1", MyModel::role1);
    5. it->setData("data 2", MyModel::role2);
    6. it->setData("data 3", MyModel::role3);
    7. model->appendRow(it);
    8.  
    9. it = new QStandardItem();
    10. it->setData("more data 1", MyModel::role1);
    11. it->setData("more data 2", MyModel::role2);
    12. it->setData("more data 3", MyModel::role3);
    13. model->appendRow(it);
    14.  
    15.  
    16.  
    17. engine.rootContext()->setContextProperty("myModel", model);
    To copy to clipboard, switch view to plain text mode 

    main.qml:
    Qt Code:
    1. TableView {
    2.  
    3. anchors.fill: parent
    4.  
    5. TableViewColumn {title: "1"; role: "one"; width: 150 }
    6. TableViewColumn {title: "2"; role: "two"; width: 150 }
    7. TableViewColumn {title: "3"; role: "three"; width: 150 }
    8.  
    9. model: myModel
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    When I run the program, tableview displays 2 row, but when I call "readXMLFile" function, Will not be added any records to the tableview.
    Last edited by neda; 28th February 2016 at 07:06.

  9. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display data from XML file in TableView

    Quote Originally Posted by neda View Post
    When I run the program, tableview displays 2 row, but when I call "readXMLFile" function, Will not be added any records to the tableview.
    Your readXMLFile function does not work on the model you have exposed to QML.

    Just have the model as a member of MyXML, then you can access it via property just like the list in comment #3

    Cheers,
    _

  10. The following user says thank you to anda_skoa for this useful post:

    neda (28th February 2016)

  11. #9
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Display data from XML file in TableView

    Quote Originally Posted by anda_skoa View Post
    Your readXMLFile function does not work on the model you have exposed to QML.

    Just have the model as a member of MyXML, then you can access it via property just like the list in comment #3

    Cheers,
    _
    Thank you.
    I got it.
    But what should I do to correct the code.
    Please guide me with simple code.
    Last edited by neda; 28th February 2016 at 12:37.

  12. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display data from XML file in TableView

    I am afraid I don't understand.
    You already have all the code, you are just working with two instances of the model instead of one.

    So don't create a model instance in main(), just create the MyXML object and let it have the model.
    Like you did with the list in comment #3.

    Cheers,
    _

  13. The following user says thank you to anda_skoa for this useful post:

    neda (29th February 2016)

Similar Threads

  1. How to export data in tableview to an excel file?
    By drunknight in forum Qt Programming
    Replies: 2
    Last Post: 31st December 2013, 03:39
  2. Preventing display spinbox in tableview cells
    By alizadeh91 in forum Qt Programming
    Replies: 2
    Last Post: 30th December 2012, 12:48
  3. display custom widget in a TableView
    By code_talker in forum Qt Programming
    Replies: 4
    Last Post: 4th August 2012, 22:40
  4. TableView/Model Display Question
    By SixDegrees in forum Qt Programming
    Replies: 9
    Last Post: 27th August 2010, 10:06
  5. getting data from tableView
    By mkarakaplan in forum Newbie
    Replies: 1
    Last Post: 7th November 2007, 10:51

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.