Results 1 to 4 of 4

Thread: QDomDocument & OS Crash on doc.createElementNS

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy QDomDocument & OS Crash on doc.createElementNS

    Why this crash ...?

    is an other method to debug?


    Qt Code:
    1. QString Gui_Tidy::Createtag(QString inputfile,QString set_lang)
    2. {
    3. QString inside="File not found!";
    4. qDebug() << "### open file " << inputfile;
    5. QFile file(inputfile);
    6. if (file.exists()) {
    7. qDebug() << "### file found ok " << inputfile;
    8. if (file.open(QFile::ReadOnly | QFile::Text)) {
    9. inside =file.readAll();
    10. file.close();
    11. }
    12. }
    13. QDomDocument doc("shghshsh");
    14. QDomElement root = doc.createElement("root");
    15. doc.createElementNS("http://www.pulitzer.ch/2005/shop/shema/1.0/","s");
    16. doc.createElementNS("http://www.pulitzer.ch/2005/PuliCMS/1.0","cms");
    17. doc.appendChild(root);
    18. QDomElement page = doc.createElementNS("http://www.pulitzer.ch/2005/PuliCMS/1.0","page");
    19. root.appendChild(page);
    20. QDomAttr language = e.attributeNode("la");
    21. language.setValue(set_lang);
    22. page.setAttributeNodeNS(language);
    23. QDomText t = doc.createTextNode(inside); /* filter self text? */
    24. page.appendChild(t);
    25. QString xml = doc.toString();
    26. qDebug() << "### xml result " << xml;
    27. return xml;
    28. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomDocument & OS Crash on doc.createElementNS

    Have you tried doing a stack-trace using a debugger? Is doc NULL?

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDomDocument & OS Crash on doc.createElementNS

    Quote Originally Posted by patrik08
    Why this crash ...?

    is an other method to debug?
    Maybe this thread helps.
    Qt Code:
    1. // createElementNS() returns the newly created element,
    2. // following 2 lines have no point at all..
    3. doc.createElementNS("http://www.pulitzer.ch/2005/shop/shema/1.0/","s");
    4. doc.createElementNS("http://www.pulitzer.ch/2005/PuliCMS/1.0","cms");
    5.  
    6. // you initialize an empty (null) element and then ask for it's "la" attribute?
    7. QDomAttr language = e.attributeNode("la");
    8. language.setValue(set_lang);
    9. page.setAttributeNodeNS(language);
    10. // i guess it should be more like this (instead of those 4 wicked lines)
    11. // page.setAttribute("la", set_lang);
    To copy to clipboard, switch view to plain text mode 
    [/QUOTE]
    J-P Nurmi

  4. #4
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDomDocument & OS Crash on doc.createElementNS

    So is running but xml is no utf8 ..... or no unicode....

    i like text on xml file so on server cms.... (i tested tidy or qt4 asci and textstream codec)

    I have a php function "utf8_to_unicode" but is not possibel to run on qt4 ....

    original function unicode xml files ... http://ppk.ciz.ch/format/qt/Multi_Language.phps


    Is not possibel to post this text on forum.... on post rewrites....

    The reusult on the cms i can write any language.... this is text from image...
    提契诺州的美味佳肴具有意大利风格,同时具有自己的独特之处。纯正的本地风味可以在这个地区特有的"tra ttorie", "grotti"(客栈)或是餐馆中享用,它们都是流行的聚会场所,最初却是冬季出售葡萄酒和熟食 的小店。

    提契诺葡萄酒中的极品无疑当数源自法国波尔多地区的墨尔乐红葡萄酒。自19世纪初开始从法国引进这种葡萄酒 以取代当地葡萄酒以来,墨尔乐葡萄酒就适应了提契诺州的气候,并在这里取得了辉煌的成功。


    Qt Code:
    1. QString Gui_Tidy::Createtag(QString inputfile,QString set_lang)
    2. {
    3. QString inside="File not found!";
    4. qDebug() << "### open file " << inputfile;
    5. QFile file(inputfile);
    6. if (file.exists()) {
    7. qDebug() << "### file found ok " << inputfile;
    8. if (file.open(QFile::ReadOnly | QFile::Text)) {
    9. inside =file.readAll();
    10. file.close();
    11. }
    12. }
    13. QDomDocument doc("");
    14. QDomElement root = doc.createElement("root");
    15. root.setAttribute("xmlns:s","http://www.pulitzer.ch/2005/shop/shema/1.0/");
    16. root.setAttribute("xmlns:cms","http://www.pulitzer.ch/2005/PuliCMS/1.0/");
    17. doc.appendChild(root);
    18. QDomElement page = doc.createElement("cms:page");
    19. page.setAttribute("xmlns:cms","http://www.pulitzer.ch/2005/PuliCMS/1.0/");
    20. page.setAttribute("la",set_lang);
    21. QDomText t = doc.createTextNode(inside);
    22. page.appendChild(t);
    23. root.appendChild(page);
    24. QString xml = doc.toString();
    25. QByteArray ilmiofile = xml.toAscii();
    26. qDebug() << "### xml result " << ilmiofile.data();
    27. return ilmiofile.data();
    28. }
    To copy to clipboard, switch view to plain text mode 

    Only this qt function transorm a xml utf8 ... but on qtextedit show normal iso....

    Qt Code:
    1. bool Gui_Tidy::file_put_contents_utf8(QString fullFileName,QString xml)
    2. {
    3. QTextCodec *codecutf8 = QTextCodec::codecForMib(106);
    4. /*QTextCodec *codeclatin1 = QTextCodec::codecForMib(4);*/
    5.  
    6. QString data = xml+"\n";
    7. QFile f( fullFileName );
    8. if ( f.open( QFile::WriteOnly | QFile::Text ) )
    9. {
    10. QTextStream sw( &f );
    11. sw.setCodec(codecutf8);
    12. sw << data;
    13. f.close();
    14. return true;
    15. }
    16. return false;
    17. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 19th June 2006 at 17:33. Reason: changed [ code ] to [ quote ] to allow wrapping of long lines

Similar Threads

  1. Crash: using a dialog in a model
    By Brandybuck in forum Qt Programming
    Replies: 3
    Last Post: 11th April 2006, 01:39
  2. Adding whitespace in QDomDocument
    By jakamph in forum Newbie
    Replies: 4
    Last Post: 6th February 2006, 22:06

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
  •  
Qt is a trademark of The Qt Company.