How to add big size text to a TextEdit ,without CPU rapid rising.
-
I used append() to add text first,but it will start a new line every calling.So I used insertPlaintext instead..but it would cost much CPU resources when the size of text become large.
So I check the source code,I find that, append function use insertblock() ,this function make a new line.,and this function mak cpu cost very low.whatever the text size is,the cpu cost is 1%. -
Welcome to devnet qt,
May be this help u. Read out it.
http://qt-project.org/doc/qt-4.8/richtext-advanced-processing.html
-
[quote author="ankursaxena" date="1402289181"]Welcome to devnet qt,
May be this help u. Read out it.
http://qt-project.org/doc/qt-4.8/richtext-advanced-processing.html[/quote]
I read the page,the example code uses "insertblock()"function which will start a new line.But I do not want this result. -
Is there a method make QTextEdit add text but do not start a new line,and even through the text size is very large,app can still run fast.
-
I have read about insertblock(). and I found something which may be important for you.
"Text strings can be inserted into the document with the insertText() function, blocks (representing new paragraphs) can be inserted with insertBlock()."
"Existing fragments of text can be inserted with insertFragment() but, if you want to insert pieces of text in various formats, it is usually still easier to use insertText() and supply a character format."
So, may be u should not use insertBlock(). in spite of this, u should use insertText(). I don't know in what consideration u r using this. So i can't tell you what is the exact solution.
-
-
[quote author="ankursaxena" date="1402294218"]I have read about insertblock(). and I found something which may be important for you.
"Text strings can be inserted into the document with the insertText() function, blocks (representing new paragraphs) can be inserted with insertBlock()."
"Existing fragments of text can be inserted with insertFragment() but, if you want to insert pieces of text in various formats, it is usually still easier to use insertText() and supply a character format."
So, may be u should not use insertBlock(). in spite of this, u should use insertText(). I don't know in what consideration u r using this. So i can't tell you what is the exact solution.
[/quote]
I use it into a com port data reading app.I use a Qthread read the data continually.And when I read new data I put it into TextEdit.
I want the data displayed without newline.So I used insertText() first.But when App run a period of time, the CPU is high.So I use append() instead.but append have newline. -
Have you tried setText() method ??
like:
QString tt = "Any Text" ;
ui->textEdit->setText(tr("hello %1").arg(tt)); -
I tried this method ,but the CPU was very high.
[quote author="ankursaxena" date="1402296578"]Have you tried setText() method ??like:
QString tt = "Any Text" ;
ui->textEdit->setText(tr("hello %1").arg(tt));
[/quote] -
Memory leak would be the reason for such higher CPU utilisation . Please keep this thing into consideration.
-
Yes,I did think about.But the memory is small.less than 100MB.but CPU is more than 50%.