[Interest] How to add tidy using Qt?

Tony Rietwyk tony at rightsoft.com.au
Thu Dec 27 08:15:49 CET 2012


Hi Cheng, 

 

You didn't show how the html variable was used?  Are you sure that the html
pointer is valid?   I suggest:  

 

QByteArray ba = webView->page()->mainFrame()->toHtml().toUtf8();

const char *html = ba.constData();

...

 

In your original code, the temporary string and byte array were being
destroyed after that statement, causing a dangling pointer in html.  Even if
it looked valid immediately after, subsequent allocations would have made
the area appear corrupt.  By keeping a reference to the temporary, you
ensure that it will be valid for the whole block.  

 

Tony.

 

 

From: interest-bounces+tony=rightsoft.com.au at qt-project.org
[mailto:interest-bounces+tony=rightsoft.com.au at qt-project.org] On Behalf Of
??
Sent: Thursday, 27 December 2012 4:52 PM
To: Qt Interest
Subject: [Interest] How to add tidy using Qt?

 

Hi, there! I want to add tidy as library into Qt program where I use some
code as following:

const char* html =
webView->page()->mainFrame()->toHtml().toUtf8().constData();
// ...
TidyBuffer output;
Bool ok = tidyOptSetBool(tdoc, TidyXmlOut, yes);
tidySetCharEncoding(tdoc, "utf8");
tidySaveBuffer(tdoc, &output);
QByteArray ret = QByteArray(reinterpret_cast<char*>(output.bp),output.size);

But I got warning: 

UTF-8 decoding error of 1 bytes : 0xff = U+0255lx 

UTF-8 decoding error of 1 bytes : 0xff = U+0255lx

UTF-8 decoding error of 1 bytes : 0xe8 = U+0008lx

UTF-8 decoding error of 1 bytes : 0xe8 = U+0008lx

UTF-8 decoding error of 1 bytes : 0xfd = U+0001lx

UTF-8 decoding error of 1 bytes : 0xfd = U+0001lx

UTF-8 decoding error of 1 bytes : 0xfd = U+0001lx

UTF-8 decoding error of 1 bytes : 0xfd = U+0001lx


I've no idea how this happen. Could you help me? Thank you!

Cheng Liang
Nanjing, China
http://www.devbean.info 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121227/8d0504cc/attachment.html>


More information about the Interest mailing list