Results 1 to 5 of 5

Thread: Display '<' as HTML in QString

  1. #1
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Display '<' as HTML in QString

    Greetings,

    I want to display the '<' character within some HTML text in a QMessageBox. It appears that Qt views the '<' character as the start of a tag and doesn't display it.

    Displaying the following in a browser does work.
    Qt Code:
    1. <html><</html>
    To copy to clipboard, switch view to plain text mode 

    Does anyone know if this is even possible in Qt?

    The following code works for any characters I use except '<'.
    Qt Code:
    1. QString str( QString( "Restricted characters found in device name: \"%1\"<br>" ).arg( sTypedName ) );
    2. QString str2( QString( "Device name \"%1\" will become \"%2\".<br>" ).arg( sOldName ).arg( sNewName ) );
    3. str.append( "<DIV align=\"center\"><TABLE>" );
    4. str.append( "<TR><TD> Restricted:</TD><TD><b><</b></TD><TD><b>></b></TD></TR>" );
    5. str.append( "<TR><TD>Replacement:</TD><TD><b>[</b></TD><TD><b>]</b></TD></TR>" );
    6. str.append( "</TABLE></DIV><br>" );
    7. str.append( str2 );
    8. int rVal = QMessageBox::warning( this, tr("Restricted Characters Found"), str,
    9. QMessageBox::Ok, QMessageBox::Cancel );
    10. if ( rVal == QMessageBox::Cancel )
    11. return false;
    12.  
    13. return true;
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display '<' as HTML in QString

    Quote Originally Posted by mclark View Post
    Displaying the following in a browser does work.
    Qt Code:
    1. <html><</html>
    To copy to clipboard, switch view to plain text mode 
    But it shouldn't.

    Use &lt; instead.

  3. #3
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display '<' as HTML in QString

    The "<html><<html>" was just an example. I saved it as a file and pointed IE to it. IE displayed "<". I was trying to show that IE can display an HTML '<'.

    The problem I'm having is that I cannot display a '<' character in a QString with other HTML tags. If I replace the '<' with &lt in the original example, "&lt" is displayed, not '<'.

    Or, when not using any HTML tags, Qt thinks a string containing '<' and '>' characters is HTML and may display incorrect characters. For example, if I have a string "Test<s>\nThis is a test.". The "<s>" will cause any following text ("This is a test.") to be struckout.

    So, the question remains, can a '<' character be displayed via Qt as HTML?

    A second question, can I display a QString with "<s>" or "<b>" or any other tag-like text in it and not have Qt treat it as HTML?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display '<' as HTML in QString

    Quote Originally Posted by mclark View Post
    If I replace the '<' with &lt in the original example, "&lt" is displayed, not '<'.
    Because it should be "&lt;", not "&lt".

    Quote Originally Posted by mclark View Post
    A second question, can I display a QString with "<s>" or "<b>" or any other tag-like text in it and not have Qt treat it as HTML?
    No, HTML standard says that everything between < and > is a tag. Use &lt; and &gt; instead.

  5. The following user says thank you to jacek for this useful post:

    mclark (6th July 2007)

  6. #5
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display '<' as HTML in QString

    Thanks jacek! I knew there had to be a way.

    Who knew that semi-colons could be so important

Similar Threads

  1. Is there a widget for display HTML files?
    By JeffJones in forum Newbie
    Replies: 6
    Last Post: 24th May 2007, 19:29
  2. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  3. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  4. Widget to display an HTML page ?
    By probine in forum Qt Tools
    Replies: 3
    Last Post: 11th October 2006, 18:55
  5. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10

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.