PDA

View Full Version : textBrowser->setSource() end-of-line



gib
20th April 2011, 01:57
I'm using QTextBrowser with setSource() to display the contents of a text file. The problem is that EOL in the text file is ignored (actually treated as a space). I've tried setting EOL in the file to both DOS and Unix versions, but it makes no difference. How can I get QTestBrowser to apply a CR at the end of the text lines?

Thanks
Gib

high_flyer
20th April 2011, 09:25
I've tried setting EOL in the file to both DOS and Unix versions, but it makes no difference.
can you show your code?

gib
20th April 2011, 09:44
can you show your code?

There isn't much to show:

QString infoFile = "info.txt";
ui->textBrowser->setSource(infoFile);

info.txt is a text file with multiple lines. In the QTextBrowser widget the lines are all concatenated, with spaces in place of the CR-LF.

high_flyer
20th April 2011, 10:46
but you said:

I've tried setting EOL in the file to both DOS and Unix versions,
So how/where did you try to set EOL?

gib
21st April 2011, 00:22
but you said:

So how/where did you try to set EOL?

In my text editor (where I created info.txt) I have the option of setting end-of-line to DOS format (CR-LF) or Unix format (LF). I've tried saving the file with each format, and in both cases QTextBrowser just concatenates all the lines in the display.

Added after 1 56 minutes:


but you said:

So how/where did you try to set EOL?

I have now tried converting my text file to rich text (by saving it as .rtf in Word Pad). Now EOL is displayed as \par, with the same concatenation. At the head of the displayed text I see what is presumably the formating info for the rich text:
{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}} {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\lang1033\f0\fs22

I'm wondering if QTextBrowser was designed just for html, but the docs say:
"The QTextBrowser class provides a rich text browser with hypertext navigation."

high_flyer
21st April 2011, 08:51
what happens if you open your original file with a simple text editor line notepad or wordpad?

gib
21st April 2011, 22:19
what happens if you open your original file with a simple text editor line notepad or wordpad?

Sorry, I don't understand the question. As I said, I created the original file with a simple text editor, and then an RTF version with Wordpad. There's nothing special about these files. I've tested with other text files, and the result is always the same - loss of formatting when displayed in QTextBrowser. I'm using Qt 4.7.0, BTW.

high_flyer
23rd April 2011, 16:32
Did you try with QTextEdit?

gib
24th April 2011, 00:05
Did you try with QTextEdit?

QTextEdit does not have a member SetSource(). I chose to use QTextBrowser because I wanted to use SetSource(). I'm aware that I could achieve what I want by reading from the text file and writing to a QTextEdit widget. My query concerns getting EOLs recognized in QTextBrowser. Is the observed behaviour (replacement of EOL by space) also intended (i.e. is it a bug or a feature)?