0

I have a simple DOM model for working with XML (from this tutorial: http://doc.qt.io/qt-5/qtwidgets-itemviews-simpledommodel-example.html). Now in my code I want to get data by index like this:

auto data = model_->data(index, Qt::DisplayRole);

But method data() returns QVariant and I want to convert it to QDomNode. How can I do that? I have tried this: https://stackoverflow.com/a/24363059/5955876, but it didn't help. I guess it is because QDomNode isn't QObject. Any suggestions?

Count Zero
  • 495
  • 6
  • 15

1 Answers1

0

You don't need to use the data() function of our model. What you need is just extracting QDomNode object from the model index. I.e.:

[..]
QModelIndex index =  model_->index(row, column);
DomItem *item = static_cast<DomItem *>(index.internalPointer());
QDomNode node = item->node();
vahancho
  • 20,808
  • 3
  • 47
  • 55