|
|
On 14.11.06 07:24:08, Peter Hackett wrote:
> I'm trying to use the QDom XML interface with the Model system.
> My problem is also with how to use the QModelIndex internal pointer.
Have you had a look at the simple dom model example?
> This is difficult to do because QDom returns QDomNode's (not QDomNode&
> or QDomNode*) If you do QAbstractItemModel::createIndex(row,col,&QDomNode)
> You are taking the address of something on the stack (the value returned
> from the QDom function that gives you a QDomNode)
The simple dom model also uses a wrapper around the QDom Nodes and
creates instances of that on the heap and put it into the model index.
> My first though was to create a Set with the addresses of QDomNode pointer
> created like this QDomNode* pQDomNode = new QDomNode(returnedFromQDomFunc);
> but that was problematic too. How do you know when to free the QDomNode
> pointers that you create?
Whenever the node that it points to is deleted or when you "close" the
document or at model deconstruction.
> I tried to use a STL Set to keep track of the
> pointers, but it requires a "less than" function which QDomNode doesn't
> have.
Then use a QList, that doesn't need a comparison function because it
can have duplicates.
> I know I can fix this by creating another data structure, but I guess I was
> hoping it would be easier to use QDomNode with the QModel pattern.
You can also use a QMap and internalId instead of pointer, all you'd
have to do is calculate a unique id for each unique node you have.
Andreas
--
Cheer Up! Things are getting worse at a slower rate.
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
|
|