tr字符串的梗
工作问题总结
声明:应用程序代码为前人所写,仅仅只是维护代码,暂且不论代码风格瑕疵。
结论:
使用tr“包”起来的字符串,可能会被翻译为不同的语言,此时,应用程序在不同语言环境下可能会表现BUG。
1.问题及源码追溯过程
// 应用程序调用函数1
void WinHelpManual::openFunction(QString func)
{
QWebPage *webPage = m_view_list.page();
QWebFrame *webFrame = webPage->frameAt(QPoint(, ));
QWebElement webElement = webFrame->documentElement();
webElement.evaluateJavaScript(func);
}
// 应用程序调用函数2
void WinHelpManual::openUrl()
{
QString Html = m_view_list.selectedHtml();
QString strUrlExp = "outline_[0-9]*.htm";
QRegExp urlRegExp(strUrlExp, Qt::CaseSensitive);
if (urlRegExp.indexIn(Html) != -)
{
QString strWebUrl = urlRegExp.cap(); // 匹配到的url
m_view_contents.setUrl(QUrl(m_path + strWebUrl));
}
}
// 应用程序调用函数3
bool WinHelpManual::event(QEvent *event)
{
if (event->type() == QEvent::KeyRelease)
{
QKeyEvent *ke = static_cast<QKeyEvent*> (event);
if (ke->modifiers() == PANEL_MODIFIER)
{
static int Ekey;
if (ke->key() == PANEL_BAR || ke->key() == PANEL_WAVE || ke->key() == PANEL_NUMERIC || ke->key() == PANEL_VECTOR || \
ke->key() == PANEL_MARK || ke->key() == PANEL_ITEM || ke->key() == PANEL_FORM || ke->key() == PANEL_USER || \
ke->key() == PANEL_VOLTRANGE_CLOCKWISE || ke->key() == PANEL_VOLTRANGE_ANTICLOCKWISE || ke->key() == PANEL_VOLTRANGE_AUTO\
|| ke->key() == PANEL_CURRRANGE_CLOCKWISE || ke->key() == PANEL_CURRRANGE_ANTICLOCKWISE || ke->key() == PANEL_CURRANGE_AUTO\
|| ke->key() == PANEL_EXT || ke->key() == PANEL_ACCURATE || ke->key() == PANEL_UTILITY || ke->key() == PANEL_MEASURRE\
|| ke->key() == PANEL_OTHERS || ke->key() == PANEL_SOURCE || ke->key() == PANEL_FILE || ke->key() == PANEL_INFO \
|| ke->key() == PANEL_IMAGESAVE || ke->key() == PANEL_HOLD || ke->key() == PANEL_SINGLE || ke->key() == PANEL_STROE \
|| ke->key() == PANEL_INTEG || ke->key() == PANEL_LOCALLOCK)
{
openFunction();
}
m_view_list.page()->findText("");//清除
switch (ke->key())
{
case PANEL_ESC:
case PANEL_HELP:
hide();
return true;
case PANEL_BAR:
{
Ekey = PANEL_BAR;
m_view_list.page()->findText(tr("Bar Graph Display(Bar)"));
}
break;
case PANEL_WAVE:
{
Ekey = PANEL_WAVE;
m_view_list.findText(tr("Waveform Display(WAVE)"));
}
break;
case PANEL_NUMERIC:
{
Ekey = PANEL_NUMERIC;
m_view_list.findText(tr("Numetic Data Display(NUMERIC)"));
}
break;
case PANEL_VECTOR:
Ekey = PANEL_VECTOR;
m_view_list.findText(tr("Vector Display(Vector)"));
break;
case PANEL_MARK:
{
switch (Ekey)
{
case PANEL_BAR:
m_view_list.findText(tr("Bar Display Mark (MARK)"));
break;
case PANEL_WAVE:
m_view_list.findText(tr("Waveform Display Mark(MARK)"));
break;
default:
break;
}
}
break;
case PANEL_ITEM:
{
switch (Ekey)
{
case PANEL_BAR:
m_view_list.findText(tr("Bar Display Item (ITEM)"));
break;
case PANEL_WAVE:
m_view_list.findText(tr("Waveform Display Item(ITEM)"));
break;
case PANEL_NUMERIC:
m_view_list.findText(tr("Numetic Display Item(ITEM)"));
break;
case PANEL_VECTOR:
m_view_list.findText(tr("Vector Display Item(ITEM)"));
break;
default:
break;
}
}
break;
case PANEL_FORM:
{
switch (Ekey)
{
case PANEL_BAR:
m_view_list.findText(tr("Bar Display Format(FORM)"));
break;
case PANEL_WAVE:
m_view_list.findText(tr("Waveform Display Format(FORM)"));
break;
case PANEL_NUMERIC:
m_view_list.findText(tr("Numetic Display Format(FORM)"));
break;
case PANEL_VECTOR:
m_view_list.findText(tr("Vector Display Format(FORM)"));
break;
default:
break;
}
}
break;
case PANEL_USER:
m_view_list.findText(tr("Numetic Data Display(NUMERIC)"));
break;
case PANEL_TAB:
if (m_view_contents.hasFocus())
{
m_view_contents.setFocusPolicy(Qt::NoFocus);
m_view_list.setFocus();
p_curWebView = &m_view_list;
repaint();
}
else if (m_view_list.hasFocus())
{
m_view_list.setFocusPolicy(Qt::NoFocus);
m_view_contents.setFocus();
p_curWebView = &m_view_contents;
repaint();
}
break;
case PANEL_VOLTRANGE_CLOCKWISE:
case PANEL_VOLTRANGE_ANTICLOCKWISE:
m_view_list.findText(tr("Voltage Range(RANGE UP/DOWN (V))"));
break;
case PANEL_VOLTRANGE_AUTO:
m_view_list.findText(tr("Auto Voltage Range(AUTO (V))"));
break;
case PANEL_CURRRANGE_CLOCKWISE:
case PANEL_CURRRANGE_ANTICLOCKWISE:
m_view_list.findText(tr("Current Range (RANGE UP/DOWN (A))"));
break;
case PANEL_CURRANGE_AUTO:
m_view_list.findText(tr("Auto Current Range(AUTO (A))"));
break;
case PANEL_EXT:
m_view_list.findText(tr("External Current Sensor Range (EXT SENSOR; option)"));
break;
case PANEL_ACCURATE:
m_view_list.findText(tr("Line Filter(LINE FILTER)"));
break;
case PANEL_UTILITY:
m_view_list.findText(tr("Utility (UTILITY)"));
break;
case PANEL_MEASURRE:
m_view_list.findText(tr("Computation(MEASURE)"));
break;
case PANEL_OTHERS:
m_view_list.findText(tr("Combination Display (COMBINE)"));
break;
case PANEL_SOURCE:
m_view_list.findText(tr("Measurement period(SYNC SOURCE)"));
break;
case PANEL_FILE:
m_view_list.findText(tr("File(File)"));
break;
case PANEL_INFO:
m_view_list.findText(tr(""));
break;
case PANEL_IMAGESAVE:
m_view_list.findText(tr("Screen capture function (Image )"));
break;
case PANEL_HOLD:
m_view_list.findText(tr("Holding Measured Values(HOLD)"));
break;
case PANEL_SINGLE:
m_view_list.findText(tr("Single Measurement(SINGLE)"));
break;
case PANEL_STROE:
m_view_list.findText(tr("Data Storage"));
break;
case PANEL_INTEG:
m_view_list.findText(tr("Integrated Power(Watt hours)"));
break;
case PANEL_LOCALLOCK:
m_view_list.findText(tr("Touch Unlock"));
break;
default:
return true;
}
openUrl();
}
}
return QWidget::event(event);
}
// QWebView page() 接口源码
QWebPage *QWebView::page() const
{
if (!d->page)
{
QWebView *that = const_cast<QWebView *>(this);
that->setPage(new QWebPage(that));
}
return d->page;
}
// QWebView findText() 接口源码
bool QWebView::findText(const QString &subString, QWebPage::FindFlags options)
{
if (d->page)
{
return d->page->findText(subString, options);
}
return false;
}
// QWebPage findText() 接口源码
bool QWebPage::findText(const QString &subString, FindFlags options)
{
return d->findText(subString, static_cast<QWebPageAdapter::FindFlag>(options.operator int()));
}
// QWebPagePrivate findText() 接口源码
bool QWebPageAdapter::findText(const QString& subString, FindFlag options)
{
::WebCore::FindOptions webCoreFindOptions = ; if (!(options & FindCaseSensitively))
{
webCoreFindOptions |= WebCore::CaseInsensitive;
} if (options & FindBackward)
{
webCoreFindOptions |= WebCore::Backwards;
} if (options & FindWrapsAroundDocument)
{
webCoreFindOptions |= WebCore::WrapAround;
} if (options & FindAtWordBeginningsOnly)
{
webCoreFindOptions |= WebCore::AtWordStarts;
} if (options & TreatMedialCapitalAsWordBeginning)
{
webCoreFindOptions |= WebCore::TreatMedialCapitalAsWordStart;
} if (options & FindBeginsInSelection)
{
webCoreFindOptions |= WebCore::StartInSelection;
} if (options & HighlightAllOccurrences)
{
if (subString.isEmpty())
{
page->unmarkAllTextMatches();
return true;
} return page->markAllMatchesForText(subString, webCoreFindOptions, /*shouldHighlight*/ true, /*limit*/ );
} if (subString.isEmpty())
{
page->mainFrame()->selection()->clear();
Frame* frame = page->mainFrame()->tree()->firstChild();
while (frame)
{
frame->selection()->clear();
frame = frame->tree()->traverseNextWithWrap(false);
}
} return page->findString(subString, webCoreFindOptions);
}
// Page findString() 接口源码
bool Page::findString(const String& target, FindOptions options)
{
if (target.isEmpty() || !mainFrame())
{
return false;
} bool shouldWrap = options & WrapAround; Frame* frame = focusController()->focusedOrMainFrame();
Frame* startFrame = frame;
do
{
if (frame->editor().findString(target, (options & ~WrapAround) | StartInSelection))
{
if (frame != startFrame)
{
startFrame->selection()->clear();
} focusController()->setFocusedFrame(frame);
return true;
}
frame = incrementFrame(frame, !(options & Backwards), shouldWrap);
} while (frame && frame != startFrame); // Search contents of startFrame, on the other side of the selection that we did earlier.
// We cheat a bit and just research with wrap on
if (shouldWrap && !startFrame->selection()->isNone())
{
bool found = startFrame->editor().findString(target, options | WrapAround | StartInSelection);
focusController()->setFocusedFrame(frame);
return found;
} return false;
}
// Page mainFrame() 成员方法源码
Frame* mainFrame() const { return m_mainFrame.get(); }
// Editor findString() 成员方法源码
bool Editor::findString(const String& target, FindOptions options)
{
VisibleSelection selection = m_frame->selection()->selection();
RefPtr<Range> resultRange = rangeOfString(target, selection.firstRange().get(), options);
if (!resultRange)
{
return false;
} m_frame->selection()->setSelection(VisibleSelection(resultRange.get(), DOWNSTREAM));
m_frame->selection()->revealSelection();
return true;
}
2.问题原因
tr翻译后导致字符串查找失败。
如上实例,因为tr“包”起来的字符串被翻译为不同语言,但是每次与之比较匹配的字符串始终为英语版本。
所以,总出现匹配失败的异常,导致调试排除浪费很长时间,在此特别备录。
Good Good Study, Day Day Up.
顺序 选择 循环 总结
tr字符串的梗的更多相关文章
- QT 随笔目录
[1]基础部分 <信号和槽机制> <信号与槽知识点> <QString 与 string转换> <QT 继承QWidget && 继承QDia ...
- python中字符串操作--截取,查找,替换
python中,对字符串的操作是最常见的,python对字符串操作有自己特殊的处理方式. 字符串的截取 python中对于字符串的索引是比较特别的,来感受一下: s = '123456789' #截取 ...
- 【linux】学习5
鸟哥那本书第11章的内容 管理整个计算机硬件的是操作系统的内核(kernel),内核是需要保护的,我们一般用户只能通过shell来跟内核通信.Shell是用户操作系统的接口 cat /etc/pas ...
- Qt国际化(Q_DECLARE_TR_FUNCTIONS() 宏给非Qt类添加翻译支持,以前没见过QTextEncoder和QTextDecoder和QLibraryInfo::location()和QEvent::LanguageChange)
Internationalization with Qt 应用程序的国际化就是使得程序能在国际间可用而不仅仅是在本国可用的过程. Relevant Qt Classes andAPIs 以下的类支持Q ...
- lunx命令2
测试网络 ping 查看ip ifconfig 关闭防火墙 iptables -F 干掉nginx进程 killall nginx 切换用户 su linux下连接另一台linux服务区 ssh ro ...
- 12.QT4.7.4-解决WIN平台和Linux平台中文乱码,QLineEdit右击菜单中文显示
1.解决Win平台中文显示 1.1首先解决win平台上中文显示乱码问题 1)首先查看qt creator的编码格式 通过->编辑->选择编码 查看. 2)如果qt creator的编码格式 ...
- 20190320 Dojo常用方法总结
0. 使用环境 Dojo版本:1.14.2 此次总结以dojo的base为主,即不需要手动引入组件 1. 常用不归类方法 1.1. dojo.addOnLoad 在页面加载完成并且dojo.requi ...
- C/C++ -- Gui编程 -- Qt库的使用 -- Qt5试用
1.头文件<QtGui>变成了<QtWidgets> 相应<QtGui/***>变成了<QtWidgets/***> 2.QTextCodec::set ...
- 如何用javasript对Gridview的项目进行汇总统计?
当我们在gridview显示统计信息时,都会想在gridview最后一行显示[小计]结果,但gridview的话好像比较难搞(至少我也不会呀 囧~),那么我就结合jquery写了一个解决方案,下面举个 ...
随机推荐
- 虚拟机VirtualBox与CentOS 7安装
一.VirtualBox 我们电脑的操作系统一般都是Windows,如果我们要学习Linux,那么可以在我们的电脑上装个虚拟机,然后在这虚拟机上安装Linux.虚拟机可以用VirtualBox 或者 ...
- net use共享文件访问
NET USE "\\xxx.xxx.xxx.xxx\vms\Application Files" "password123" /USER:"ap\1 ...
- apache在mac下403问题
症状:在mac下使用xampp环境,httpd.conf权限,但访问网站报403错误. 解决方案:将对应文件目录权限改为755 修改后,Thinkphp访问提示Application不可写,无法创建内 ...
- “我的小程序”来了 新版微信v6.7.1下拉就能找到
今天iOS版微信迎来v6.7.1正式版发布,本次升级主要是可以把常用的小程序添加到“我的小程序”.近期版本微信可以直接浏览订阅号的消息,扫一扫可拍照翻译整页中英文,浏览的文章支持缩小为浮窗.两大更新如 ...
- laravel用crud修改产品items-新建resource controller和routing
前面我们创建了laravel简单的items产品api,但是需要在数据库添加,如何在网页上直接添加呢?我们可以用view来操作crud(增加Create.读取查询Retrieve.更新Update和删 ...
- MySQL之——崩溃-修复损坏的innodb:innodb_force_recovery
转: https://blog.csdn.net/l1028386804/article/details/77199194 一.问题描述 今天在线运行的一个mysql崩溃了. 查看错误日志,如下: - ...
- docker的容器和镜像的差别
- LuaFileSystem
bokeyuan_1234 lua的文件管理 lua没有自己的文件管理 只有读取和写入文件,但是可以通过调用lfs(LuaFileSystem),lfs是一个 用于lua进行文件访问的库,支持lua5 ...
- [Java in NetBeans] Lesson 17. File Input/Output.
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...
- 搭建redsocks 测试环境
1. 先来谈谈pc的测试环境 socks5代理,因为要在centos下设置,没有yum到socks, 就安装ss5,wget http://jaist.dl.sourceforge.net/proje ...