Results 1 to 9 of 9

Thread: textBrowser->setSource() end-of-line

  1. #1
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question textBrowser->setSource() end-of-line

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: textBrowser->setSource() end-of-line

    I've tried setting EOL in the file to both DOS and Unix versions, but it makes no difference.
    can you show your code?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: textBrowser->setSource() end-of-line

    Quote Originally Posted by high_flyer View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: textBrowser->setSource() end-of-line

    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?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: textBrowser->setSource() end-of-line

    Quote Originally Posted by high_flyer View Post
    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:


    Quote Originally Posted by high_flyer View Post
    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."
    Last edited by gib; 21st April 2011 at 02:44.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: textBrowser->setSource() end-of-line

    what happens if you open your original file with a simple text editor line notepad or wordpad?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: textBrowser->setSource() end-of-line

    Quote Originally Posted by high_flyer View Post
    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: textBrowser->setSource() end-of-line

    Did you try with QTextEdit?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: textBrowser->setSource() end-of-line

    Quote Originally Posted by high_flyer View Post
    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)?

Similar Threads

  1. Time in textBrowser
    By NewLegend in forum Qt Programming
    Replies: 13
    Last Post: 12th October 2010, 05:37
  2. space in textBrowser
    By NewLegend in forum Qt Programming
    Replies: 4
    Last Post: 3rd September 2010, 20:04
  3. New Line in textBrowser
    By NewLegend in forum Qt Programming
    Replies: 4
    Last Post: 12th August 2010, 06:29
  4. QTextBrowser setSource (Qt 4.2.2)
    By manojmka in forum Qt Programming
    Replies: 0
    Last Post: 10th January 2008, 08:00
  5. Textbrowser issue
    By deekayt in forum Qt Programming
    Replies: 1
    Last Post: 29th October 2006, 08:51

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.