Registered Member
|
Hi all,
I'v been trying to create a config file for my Amarok script with XML (QDomElement). I based my script on an C++ sample. However, I only get an empty XML tree. The code below is my example.
Can somebody tell me what I'm doing wrong? Tim |
Registered Member
|
Is there no-one who can help me with this?
Or do I have to ask my question somewhere else? |
Registered Member
|
I do not know anything about these scripts, but I would guess that the file is not found and that is why you get back an empty parse tree. You should provide a valid path, not only the file name.
|
Registered Member
|
Actualy, the small demo code I provide is not yet meant to write to (or read from) a file, but to create the XML tree in memory and the show the generated code in a message box.
So if the had code workd, it shoold create in memory a XML tree containing only one node. And when the message box appears it shoold show somthing like this: "<config></config>". But it doesn't work and it only displays an empty string. So I'm wondering why. |
Registered Member
|
You can't construct QDomElements that way. Use QDomDocument.createElement(tagname).
For more info, see: http://doc.trolltech.com/4.6/qdomdocument.html as well as related classes: http://doc.trolltech.com/4.6/classes.html. That documentation is for C++, but if you disregard variable types most of it applies to QtScript as well. |
Registered Member
|
Hi jmrk,
I tried to translate the C++ example in [url]http://doc.trolltech.com/4.6/qdomdocument.html[/ur] to QtScript but my string is still empty. This is the original code:
My translated code:
|
Registered Member
|
hm... sorry, no idea what's wrong now.
I don't see any mistakes in your translation to QtScript. But I can confirm that it doesn't work as expected. It looks as if the .toString() method simply didn't care about anything you inserted using .appendChild(), but as far as I understand it, that's not the intended behavior of .toString(). In C++, the example works, so this might be a bug somewhere in the QtScript framework, or a QtScript related peculiarity that I have no clue about. |
Registered Member
|
Well, actually, I don't think the toString() function is the problem. Because when I load an XML file the toString() function works without any problems.
It's more like the appendChild function doesn't work. Because hen you do doc.hasChildNodes() it returns false. At the moment I solved it the old fashion way by building a string and writing that to a file but it would be nice to just have it work. |
Registered Member
|
Is there a return value for appendChild? You might want to check this and narrow down where exactly the problem is caused.
If this is a bug, you may want to file a bug report to get it fixed. |
Registered users: Bing [Bot], Evergrowing, Google [Bot], Sogou [Bot]