Results 1 to 2 of 2

Thread: How to prevent QTextBrowser/QTextDocument from blocking?

  1. #1
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default How to prevent QTextBrowser/QTextDocument from blocking?

    I am using QTextBrowser to display some large html pages.

    Before I show the data, I spawn a little QMovie loading indicator, and then I call

    Qt Code:
    1. class ResultBrowser : public QTextBrowser
    2. {
    3.  
    4. void showcontent(const QString& s);
    5. QTextDocument mTextDocument;
    6.  
    7. };
    8.  
    9. void ResultBrowser::showcontent(const QString& s)
    10. {
    11. //I use a QTextDocument for my stylesheet
    12. mTextDocument->setHtml(s);
    13. setDocument(mTextDocument);
    14. }
    To copy to clipboard, switch view to plain text mode 

    Sadly this causes some blocking which causes the loading indicator to pause. I attempted to call my showcontent function through QtConcurrent::run, but it crashes due to events being triggered from the wrong thread.

    Suggestions?

  2. #2
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to prevent QTextBrowser/QTextDocument from blocking?

    Well looking back at some other threads on a similar issue I decided to use a timer to insert the text in ~100 character chunks.

    This fixes the performance issue *yay*

    but sadly the html is not rendered properly when passed in with chunks like this, for example list items <li> don't display on their own lines

    Qt Code:
    1. void ResultBrowser::loadContent()
    2. {
    3. if(!mContent.isEmpty() && mCurrentIndex < mContent.size())
    4. {
    5. if(!mTextCursor)
    6. {
    7. mTextCursor = new QTextCursor(&mDocument);
    8. }
    9.  
    10. //No splitting tags
    11. int size = mChunkSize;
    12. int index = mContent.indexOf("<", mCurrentIndex + mChunkSize);
    13. if(index > 0)
    14. {
    15. size = index - mCurrentIndex;
    16. }
    17.  
    18. QString tmp = mContent.mid(mCurrentIndex, size);
    19.  
    20. mTextCursor->insertHtml(tmp);
    21. mCurrentIndex += size;
    22. }
    23. else
    24. {
    25. mLoadTimer->stop();
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    Is the display issue something that can be overcome? or is this a flawed tactic all together?

Similar Threads

  1. QDBusInterface blocking dbus
    By zengtao in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2012, 15:39
  2. Non-Gui thread blocking gui
    By Valheru in forum Qt Programming
    Replies: 17
    Last Post: 12th February 2010, 11:11
  3. Non blocking Gui Qthread in qt3
    By triperzonak in forum Newbie
    Replies: 2
    Last Post: 13th September 2008, 14:06
  4. ports blocking
    By babu198649 in forum General Programming
    Replies: 3
    Last Post: 4th August 2008, 15:51
  5. Blocking ftp
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 21st December 2007, 08:18

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.