PDA

View Full Version : how works Qtextedit?



radmir
12th August 2014, 07:44
Hi, all,
Anybody, who knows how QTextEdit works, help, please.
I declared
QTextEdit td;

I have an html file, I wanna do operation td.setHtml,
immediately after that I called qDebug() << td.toHtml();

But this is not the same html, I began to work. It's content has been drastically changed - some content just disappeared, how it maybe?
Is their any rules, how to prepare html?

Qt 4.8.x.

Yours,
Radmir

Lesiok
12th August 2014, 10:09
Just look at QTextEdit doc and read what is supported HTML subset (http://qt-project.org/doc/qt-4.8/richtext-html-subset.html)

radmir
12th August 2014, 19:20
Just look at QTextEdit doc and read what is supported HTML subset (http://qt-project.org/doc/qt-4.8/richtext-html-subset.html)

Not an answer, all tags are from supported set. After <body> there is simple text with its title in <h3> tags and all this upto first <ul> tag dissappears after that operation.

Radmir

aamer4yu
13th August 2014, 07:48
QTextEdit td;

If this is the code,, then td will be deleted once out of scope.

Declare on heap.

anda_skoa
13th August 2014, 10:17
But this is not the same html, I began to work. It's content has been drastically changed - some content just disappeared, how it maybe?


What kind of content did disappear?

My guess is that the text edit parses the HTML and creates is internal QTextDocument from it. When you call toHtml() it generates new HTML based on that document.

So a roundtrip might not yield the exact document, but it should have the same or very similar rendering.

Cheers,
_

radmir
13th August 2014, 15:45
If this is the code,, then td will be deleted once out of scope.

Declare on heap.

So, what?
All this is inside one block of code. So, how your actual remark explains the phenomena?

Radmir.

radmir
13th August 2014, 17:52
If this is the code,, then td will be deleted once out of scope.

Declare on heap.

So, what?
All this is inside one block of code. So, how your actual remark explains the phenomena?

Radmir.

Added after 5 minutes:

Here is an example:
initial html string is:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>

<p>this is the first string.</p>
<h2>Introduction.</h2>
<div>This sample build for testing purposes.</div>

<div><!--StartFragment-->This is second string before content<h2>Content:</h2>
<div>
<ul>
<li><b>Reference="#intro" is used for link to Introduction</b><br /></li>
<li><b>Reference="#how" is used to Chapter How it was done</b></li>
</ul></div>
This is a place for anchor How it was done
<h3>The Chapter How it was done?</h3>
<div>It was done witout any sound
</div>
</div>

</body></html>
td.toHtml() gives:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This is second string before content</p>
<p style=" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:x-large; font-weight:600;">Content:</span> </p>
<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Reference=&quot;#intro&quot; is used for link to Introduction</span><br /></li>
<li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Reference=&quot;#how&quot; is used to Chapter How it was done</span> </li></ul>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This is a place for anchor How it was done </p>
<p style=" margin-top:14px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:large; font-weight:600;">The Chapter How it was done?</span> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">It was done witout any sound </p></body></html>
The result lost three strings:
<p>this is the first string.</p>
<h2>Introduction.</h2>
<div>This sample build for testing purposes.</div>

If you cut theese strings and paste them before tag </body> you will see them again!!!

How it may be?
My rests of brains are boiled!

Radmir

radmir
14th August 2014, 05:36
Yes I guess so, may you say what really happened in the sample below in my addition yesterday, 22:52?
Radmir

radmir
14th August 2014, 11:36
To see all text one should insert the comment <!--StartFragment--> after tag <body>. Be cautious - inserting closing comment <!--EndFragment--> may produse text truncating!?

Can anybody explain this effect?

Radmir