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?
You don't need to use the data()
function of our model. What you need is just extracting QDomNode
object from the model index. Ie:
[..]
QModelIndex index = model_->index(row, column);
DomItem *item = static_cast<DomItem *>(index.internalPointer());
QDomNode node = item->node();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.