【发布时间】:2022-01-11 11:32:09
【问题描述】:
wxWidget::wxWebView->查找-https://docs.wxwidgets.org/3.0/classwx_web_view.html#ad85a7aa0351b6e6a6bffd4220f9758ee
示例代码
wxWebView *webView;
webView = wxWebView::New(this, wxID_ANY);
webView->SetPage("<html><head><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no' /><meta content='en-us' http-equiv=\"Content-Language\" /><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" /><title>Demo App</title><style type=\"text/css\">.auto-style8 {font-family: \"Bookman Old Style\";font-weight:bold;color:#734024;}.underline{color:#ff0000;}.text {color:#230fd2;}#wrapper1 { width: 100% ; display: table;}#wrapper {width: 100% ; display: table;}#header1 {color: #E6F0F1; display: table; background-color: #0000ff;width: 100% ; text-align: center;height: 50px;font-size: 105% ; font-weight: bold;}#header2 {background-color: #B98264;display: table; width: 100% ; height: 40px;text-align: center;color: #FFFFFF; font-size: 75% ; font-weight: bold;}.auto-style13 {text-decoration: underline;}.text2{color:#000000;text-align: justify;}</style></head> <body style=\"color:#000000;background-color:#FFFFFF\"><div id=\"header2\"><p style=\"font-size: x-medium\" class=\"auto-style13\">Demo Page<br></p></div> <p class=\"auto-style8\" style=\"width: 100%;\">To Start - <br/><br/>STEP 1. Select data</p></body></html>","");
long lMatchCount = webView->Find("a",wxWEBVIEW_FIND_HIGHLIGHT_RESULT );
if(lMatchCount == wxNOT_FOUND){
wxMessageBox("Search not found");
}else{
//wxMessageBox("Search found" + lMatchCount);
wxLogMessage("Matches: %s ",std::to_string(lMatchCount));
}
上面的代码可以正常工作并返回“a”的出现次数。
当 webview->SetPage 再次使用大文本动态更新(任何虚拟内容都可以)并且如果再次调用 find 调用它会因分段错误而崩溃
如果 SetPage 在第一个实例中加载了大文本,它也会崩溃,因此排除了更新导致崩溃的可能性。
还尝试从本地文件加载大文件(default.html 包含上面的 html 代码 - 替换任何长字符串,它会崩溃并返回相同的结果)
wxFile fFileIn("default.html", wxFile::read);
wxFileInputStream in(fFileIn);
webView->SetPage(in,"");
fFileIn.Close();
这里报告了类似的问题http://trac.wxwidgets.org/ticket/15207
【问题讨论】:
-
你有解决这个问题的办法吗?
-
没有.. 寻找解决方案
-
你能尝试调试一下吗?第一次运行和页面更新时有什么区别?
-
aha.. 我尝试在第一个实例本身中使用大文本运行...它因分段错误而崩溃...没有更新
-
您在处理
EVT_WEBVIEW_LOADED事件吗?你可以试试webView->SetPage(in,"");,即用CallAfter看看它是否仍然崩溃?
标签: wxwidgets