Results 1 to 18 of 18

Thread: QWebKit shows raw text

  1. #1
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QWebKit shows raw text

    I am having a strange problem with QWebKit. When I send and receive HTML data through my network, WebKit is displaying it as raw text. I admit my current network recoding is premature, but I have successfully connected to the server with an older client software and that software shows the HTML as it should.

    When I setHtml from the client itself, the HTML looks as it should. The problem currently occurs only with the data being sent across the network.

    FYI: I am using WebKit as part of the chat so that it is a rich text environment.

    I wanted to try setContent instead of setHtml, but I am not sure how to set the mimetype. Needless to say, I am using setContent wrong.

    Any pointers?

  2. #2
    Join Date
    Jun 2007
    Location
    Louisiana
    Posts
    77
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    Your problem may be in inappropriate usage. Try using QWebView to view the pages instead.

  3. #3
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    I have tried using WebView.setHtml also, that is what I tried first. No matter how I try it, the text that is sent across the network seems to loose it's HTML code and becomes raw text. Or, Plain text for that matter .. the HTML code is gone and all I see is the text.

  4. #4
    Join Date
    Jun 2007
    Location
    Louisiana
    Posts
    77
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    I have used the QWebView widget often and it works fine. Perhaps an example would be helpful.

    Here is a QWebView widget that loads an animated gif from the web and shows it in a parent object (in my case a tab widget).

    Qt Code:
    1. void DXCentral::createStereo()
    2. {
    3. // Create Web Content View //
    4. webStereo = new QWebView(tabTen);
    5. webStereo->setObjectName("webStereo");
    6. webStereo->setGeometry(3,3,260,260);
    7. connect(webStereo, SIGNAL(loadFinished(bool)), this, SLOT(slotShowStereo()));
    8.  
    9. webStereo->load(QUrl("http://stereo-ssc.nascom.nasa.gov/beacon/euvi_195_rotated.gif"));
    10. }
    11.  
    12. void DXCentral::slotShowStereo()
    13. {
    14. webStereo->show();
    15. }
    To copy to clipboard, switch view to plain text mode 

    As you can see, the object is created on a tabWidget, the URL is set and when the QWebView has it loaded - the .show() is called to make it visible. Try to substitute your URL and parent and see if this works for you.

  5. #5
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    I am not using a URL in this example. I am sending a string of text that contains HTML code.

  6. #6
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    Try the setHtml function to load your HTML in that case.

  7. #7
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    Quote Originally Posted by prof.ebral View Post
    I have tried using WebView.setHtml also, that is what I tried first. No matter how I try it, the text that is sent across the network seems to loose it's HTML code and becomes raw text. Or, Plain text for that matter .. the HTML code is gone and all I see is the text.
    Quote Originally Posted by JD2000 View Post
    Try the setHtml function to load your HTML in that case.
    I have, mentioned that.

  8. #8
    Join Date
    Jun 2007
    Location
    Louisiana
    Posts
    77
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    Then I think should use the QUrl class and retrieve unencoded text with the fromFile() method.

  9. #9
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    That's not how it works. I have no plans of Person A sending data to Person B and Person B's client putting that data into a file so it can be read. That sounds insecure.

    Honestly it sounds more like it's either a bug in Qt, or I am doing it wrong. If I connect with an older client the HTML string being sent works, it's only with the newer clients.

  10. #10
    Join Date
    Jun 2007
    Location
    Louisiana
    Posts
    77
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    As I re-read your posts it strikes me that I overlooked that you wanted to use Rich Text - NOT HTML. I think you mentioned that the use of HTML was to display Rich Text in your chat over the network.

    Is this the case? Are you having trouble with displaying transferred rich text at the receiving end of the chat exchange? Or are you mistakenly using HTML to get a richer text result?

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebKit shows raw text

    Can we see some code?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    Quote Originally Posted by ad5xj View Post
    As I re-read your posts it strikes me that I overlooked that you wanted to use Rich Text - NOT HTML. I think you mentioned that the use of HTML was to display Rich Text in your chat over the network.

    Is this the case? Are you having trouble with displaying transferred rich text at the receiving end of the chat exchange? Or are you mistakenly using HTML to get a richer text result?
    not RTF.

    Quote Originally Posted by wysota View Post
    Can we see some code?
    Yeah.. after I catch some Zs. I just recoded a horribly implemented Server <-> Client script, and while a bit buggy on my end, I have a solid foundation created for a pure Python, stackable, socket based Server <-> Client network.

  13. #13
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    So, I am not sure how much code you really need to see here.
    Qt Code:
    1. def buildHead(self):
    2. with open(path['chat_styles']+'chat.css', 'r') as f:
    3. css = f.read()
    4. self.head = '<style type="text/css">\n'
    5. self.head += css+'\n'
    6. self.head += '</style>'
    7.  
    8. def Post(self, msg):
    9. tabIndex = self.parent.center2.chatView.currentIndex()
    10. tabText = str(self.parent.center2.chatView.tabText(tabIndex))
    11. chatTabs = self.parent.center2.chatTabs
    12. chatTabs['Main Room'].chatBuffer.append(msg)
    13. chatTabs['Main Room'].scrollView(self.head, chatTabs[tabText].chatBuffer)
    To copy to clipboard, switch view to plain text mode 

    I build a head that will be the users defined CSS. In this test model I just send the chat to the 'Main Room' tab. The chat messages are placed inside a list called chatBuffer and then the list is put together.

    Qt Code:
    1. def scrollView(self, message, chatBuffer):
    2. while len(chatBuffer) > 10: chatBuffer.pop(0) # Currently shows only last 10 messages
    3. message += ''.join(chatBuffer)
    4. self.viewFrame.setHtml(message)
    5. self.viewFrame.scroll(0, 1000)
    To copy to clipboard, switch view to plain text mode 

    This allows me the user to create a chat buffer, so 1,000's of lines of chat are not soaking of their memory. Then I set the HTML in the view frame .. and I get raw text. Do you need to see more code?

    edit: Just a quick not. Oddly the setHtml works when the data comes from the client itself, but when the data is transmitted over the network it does not. I may still have an error on my end.
    Last edited by prof.ebral; 24th March 2010 at 04:36.

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebKit shows raw text

    Dump the contents of the message variable to the console before you set it as html on self.viewFrame to see if the html code is complete.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    It is complete.

    EDIT: I am almost done with the network's changes. I'll drop this issue and come back to it later. Thanks for all the help so far.

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebKit shows raw text

    Quote Originally Posted by prof.ebral View Post
    It is complete.
    Did you verify it with some validator service? Maybe there is something that you simply can't see that causes the problems.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    I will finish the network and create a new thread. The new client is having it's own problems. It just seems odd that the string would print to the console as HTML, but when I use that string to set the HTML I get raw text. I don't even get the HTML code in the raw text, just HTML stripped raw text.

  18. #18
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebKit shows raw text

    I know this thread is nearly a year old, but I wanted to post my answer to my own problem in hopes that it helps someone else in the future. So please don't bombard me with thread necromancy.

    As it turns out the problem is in the setHtml method and the fact it is occurring within a threaded method. The setHtml method cannot operate outside of the Main GUI thread, so in order for me to post the correct HTML I need to use signals and slots. All is working much better now and I hope to use WebKit as a strong platform for my rich text chat box.

Similar Threads

  1. Replies: 1
    Last Post: 29th January 2010, 13:44
  2. Need a book or website that shows how to do qt animation
    By technoViking in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2009, 05:00
  3. QWebView shows '?' instead of all images
    By doep in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2009, 10:03
  4. Program that just shows a window
    By claudio-cit in forum Newbie
    Replies: 2
    Last Post: 5th July 2008, 09:55
  5. Custom Plug-in shows but layout is messed up
    By MrGarbage in forum Qt Tools
    Replies: 2
    Last Post: 21st July 2007, 16:12

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.