Executing Javascript with low/high priority

In this example you learn about executing javascript with QApplication::ExecuteJavaScript with different priority levels.

When executing JavaScript by using QApplication::ExecuteJavaScript there exist 3 priority-levels: QJsPriority::Low , QJsPriority::Standard and QJsPriority::High Scripts with higher priority-level will be placed in the javascript execution-queue before scripts with lower ones and scripts with equal priority level are executed in order.
But knowing these three priority levels is not enough. QCubed Controls using JavaScript(i.e.: QJqButton using a JQuery UI control) have their own mechanism to execute JavaScript related to them.
QCubed task order:
  • render/update html
  • execute JavaScript returned by the controls' method GetEndScript
  • execute JavaScript from QApplication::ExecuteJavaScript with QJsPriority::High
  • execute JavaScript from QApplication::ExecuteJavaScript with QJsPriority::Standard
  • execute JavaScript from QApplication::ExecuteJavaScript with QJsPriority::Low
Take a look at the example below. By clicking on one of the buttons the datagrid gets updated and an alert box will show up. Try clicking on buttons of both rows and look at the different update-behaviour.
The interesting code resides in the methods renderButton_Click and renderLowPriorityButton_Click
In these methods the datagrid is marked as modified (render it again, including all the buttons), some JavaScript alert boxes will show up and the color of the buttons changes due to adding a css class via JavaScript. The parameter QJsPriority::Low forces the script to be executed after all scripts with higher priority.
When the buttons are (re)rendered they get their standard color applied (and the JavaScript returned by GetEndScript is executed again). If you hit a update & low priority alert button the alert boxes have low priority, the JavaScript for adding the new css class is executed before the alerts show up and the color is changed immediately. When hitting a update & alert button the color will be changed after the alert boxes show up because all scripts are executed with standard priority.
Name start standard priority javascript start low priority javascript
row1
row2
row3
row4
row5
row6
row7
row8
row9
row10