QWebElement evaluateJavaScript - speed issue



  • I am trying to optimize some part of my code that run slow with "evaluateJavaScript" lagging the UI a little bit.

    I have tried to put all my evaluateJavaScript into one and process it directly on the QWebFrame, but it's not faster (even slower).
    Is there a way to improve the speed of my calls?

    I haven't moved to QWebEngine as my project is not compatible yet (using msvc2012 and need cookie management)

    @ /// Name
    QWebElement inputNameElement = ui->webView_workouts->page()->mainFrame()->documentElement().findFirst("input[id="name-workout"]");
    QString jsValue = QString("this.value='%1';").arg("");
    inputNameElement.evaluateJavaScript(jsValue);

    /// Plan
    QWebElement inputPlanElement = ui->webView_workouts->page()->mainFrame()->documentElement().findFirst("input[id=\"plan-workout\"]");
    jsValue = QString("this.value='%1';").arg(plan);
    inputPlanElement.evaluateJavaScript(jsValue);
    
    /// Creator
    QWebElement inputCreatorElement = ui->webView_workouts->page()->mainFrame()->documentElement().findFirst("input[id=\"creator-workout\"]");
    jsValue = QString("this.value='%1';").arg("");
    inputCreatorElement.evaluateJavaScript(jsValue);
    
    
    // This is slower that above code, find out why, maybe try with QWebEngine later
    //    QString jsToExecute = "$('#name-workout').val( '' ); ";
    //    jsToExecute += QString("$('#plan-workout').val( '%1' ); ").arg((plan));
    //    jsToExecute += "$('#creator-workout').val( '' ); ";
    //    ui->webView_workouts->page()->mainFrame()->documentElement().evaluateJavaScript(jsToExecute);@


  • Still would like to know what's the best way to use evaluateJavascript()
    on the page or on the QWebElement individually? Are there best practices?
    Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.