[英]How to access HTML script variable in QT
I am someone who is new to QT. 我是QT新手。 I am creating a HTML report page in QT. 我正在QT中创建HTML报告页面。 In that I am creating a table and populating my data into it using the following: 为此,我正在创建一个表,并使用以下命令将数据填充到其中:
htmlFile.open(path);
htmlFile<<"<!DOCTYPE html><html><head></head><body>";
htmlFile<<"<table id='myTable'>"
"<tr>"
"<td>Feature</td>"
"<td>Test Count</td>"
"<td>PASS</td>"
"<td>FAIL</td>"
"<td>SKIPPED</td>"
"</tr>";
I have a script that displays the row index, column and the value of the cell.This is my script : 我有一个脚本显示行索引,列和单元格的值,这是我的脚本:
QString val;
htmlFile<<"<script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>"
"<script>"
"$(document).ready(function(){"
"$('#myTable td').click(function() {"
"var column_num = parseInt( $(this).index() ) + 1;"
"var row_num = parseInt( $(this).parent().index() )+1;"
"var txt='Row:' +row_num+' Column : '+column_num;"
"txt+=' Value: '+ document.getElementById('myTable').rows[row_num-1].cells[column_num-1].innerHTML; "
"alert(txt); }); });"
"</script>";
Now I want the variable 'txt' to be used in my class, ie, something like val=txt (which definitely is not possible directly). 现在,我希望在类中使用变量“ txt”,即类似val = txt的东西(这绝对不可能直接实现)。 Is there any way to do so? 有什么办法吗? Can a global variable help me? 全局变量可以帮助我吗?
This is my first HTML and script attempt. 这是我第一次尝试HTML和脚本。 So I ma bit confused. 所以我有点困惑。 Thanks in advance! 提前致谢!
You can use an xml parser so your html file can be load has object. 您可以使用xml解析器,以便可以将具有对象的html文件加载。 qt provide an xml parser see http://doc.qt.io/qt-4.8/qdomdocument.html qt提供xml解析器,请参阅http://doc.qt.io/qt-4.8/qdomdocument.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.