PDA

View Full Version : How to prevent QTextBrowser/QTextDocument from blocking?



Berryblue031
19th April 2011, 09:48
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




class ResultBrowser : public QTextBrowser
{

void showcontent(const QString& s);
QTextDocument mTextDocument;

};

void ResultBrowser::showcontent(const QString& s)
{
//I use a QTextDocument for my stylesheet
mTextDocument->setHtml(s);
setDocument(mTextDocument);
}



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?

Berryblue031
20th April 2011, 08:56
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



void ResultBrowser::loadContent()
{
if(!mContent.isEmpty() && mCurrentIndex < mContent.size())
{
if(!mTextCursor)
{
mTextCursor = new QTextCursor(&mDocument);
}

//No splitting tags
int size = mChunkSize;
int index = mContent.indexOf("<", mCurrentIndex + mChunkSize);
if(index > 0)
{
size = index - mCurrentIndex;
}

QString tmp = mContent.mid(mCurrentIndex, size);

mTextCursor->insertHtml(tmp);
mCurrentIndex += size;
}
else
{
mLoadTimer->stop();
}
}



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