QWebView: lags when executing JS

54 views Asked by At

I'm writing messenger for social network. That's how it works:

  1. Getting dialogs list with API
  2. Getting info (name, avatar) about users
  3. Showing that in QWebView.

Here is some code:

void Messenger::loadedMoreDialogs() {
    QString javascript;
    javascript += "html = \"" + dialogsHtml + "\";";
    javascript += "$('#dialogList').append(html);";
    javascript += "$('#name').html('" + name + "');";
    javascript += "$('#surname').html('" + surname + "');";
    javascript += "$('#loading').hide(200);";

    for (int i = 0; i < usersInfo.count; i++) {
        javascript += QString("$('#owner") + QString::number(usersInfo.list[i].id) + QString("').html('") + usersInfo.list[i].name + QString(" ") + usersInfo.list[i].surname + QString("');");
        javascript += QString("$('#avatar_dialog") + QString::number(usersInfo.list[i].id) + QString("').prop('src', '") + usersInfo.list[i].avatar_50 + QString("');");
    }
    javascript += "$('img[chat=\"1\"]').replaceWith($('<div class=\"confAvatar\"> </div>'));";
    browser->page()->mainFrame()->evaluateJavaScript(javascript);
}

So, when i'm executing JS (in last line of function), browser become frozen on ~1 second.

1

There are 1 answers

0
Efog On BEST ANSWER

Ok guys, problem solved. It was JQuery. I just removed it. No lags now.