Launchy有道翻译插件开发

Edit


一直想做一个方便查词的工具。一开始想借助OSX下面最火的Alfred,做一个插件。结果以为赚便宜淘宝上50块钱买了一个family license,结果被无良奸商骗了。license没几天就失效了,投诉无门。后来发现一直在用的Windows快捷方式神器Launchy,也支持插件开发。于是,锁定目标,做一个Launchy的有道插件。
首先看Launchy插件开发官方页。人家写清楚了环境的版本要求:

For this setup, we require Visual Studio (preferably 2005 as that is what I use) and QT 4.3.3

后来就因为版本问题走了很多弯路。

功能概述

  1. 快速进入插件 - yd<tab>
  2. 从剪贴板取单词,或自行输入

  1. 查单词 - <tab>

  1. 执行任意结果项均打开单词的有道词典页面

QT环境安装

QT4 vs.QT5

目前QT的最新版本是5.6,所以直接走官方用网络安装的都是QT5。所以一开始,傻乎乎的准备把原先的插件框架写成QT5兼容。QT4到QT5做了大规模的变化,很多特性不兼容。下面是一些参考链接

QT安装

QT有多种安装方式:

  1. 最简单的就是官网,通过网络方式安装,注意选community和open source。其他是要license fee的
  2. exe安装。以4.8.6为例,在QT archive的网站上可以下载官方用各种编译器编好的二进制安装包。

  1. 最灵活的安装方式就是编译安装了。去上面archive的网站下载源码。好处是可以编译出自己需要的编译器的版本。具体支持哪些编译平台看源码目录<Qt>\4.6.0\mkspecs\,下面列出了所有支持的开发平台。

有一点很有意思的是,在我折腾QT5的时候发现,QT5目前还不支持VS2015的编译平台,最高只支持到VS2013。
回到我们的需求上,可以看到,按照Launchy官方的指点,我们需要VS2005,以及对应的QT库,所以archive页上也没有现成的二进制安装包,只好自己编译。依然有官方指引。其实很容易,所谓会者不难。有几个地方要注意:

  1. 下载VS2005的时候一定要找靠谱的安装,否则像我一开始装的是个繁中版本,各种错误,让人很是郁闷。
  2. 一定要从VS的command prompt进去configue和compile。因为VS的command prompt会做很多环境配置。
  3. x86和x64是不同的command prompt

剩下来的按照官方的指引就可以了,简单看如下:

configure -platform win32-msvc2005
nmake

QT开发环境

官网安装的版本自带了QT Creator。所以一开始都是用他在折腾,感觉用起来还不错,没有VS那么臃肿。换到QT4.8.6以后,可能版本过低,开不起来,所以没办法要切到VS2005底下开发。然后又摸索了一阵,需要安装一个VS的QT插件。后来又是在版本上一番折腾,最终选定1.1.11,配合VS2005使用无压力。

Launchy插件开发

其实很简单,按照作者的推荐,版本一步不差,或者差的不远,都是可以跑起来的。最终版本VS2005+QT4.6.0+qt-vs-1.1.11
中间试过VS2013,如果整个Launchy用2013编译,插件也用2013编译的话,是可以用的。但是这样移植性太差了,网上下载的Launchy就没法用了。

Launchy插件

简单说一下Launchy的插件结构,以便未来如果要进一步开发又得重新学习:

插件基于消息工作

        case MSG_INIT:
init();
handled = true;
break;
case MSG_GET_LABELS: // 每个input可以打label,以后可以根据label来甄别属于哪个插件
getLabels((QList<InputData>*) wParam);
handled = true;
break;
case MSG_GET_ID:
getID((uint*) wParam);
handled = true;
break;
case MSG_GET_NAME:
getName((QString*) wParam);
handled = true;
break;
case MSG_GET_RESULTS:// 在这里为输入插入结果
getResults((QList<InputData>*) wParam, (QList<CatItem>*) lParam);
handled = true;
break;
case MSG_GET_CATALOG: // catalog是Launchy的数据库入口。对于插件数据量不大的话,可以忽略这个
getCatalog((QList<CatItem>*) wParam);
handled = true;
break;
case MSG_LAUNCH_ITEM: // 激发某个结果项,这里要注意InputData的top result
//qDebug()<<"Launch";
launchItem((QList<InputData>*) wParam, (CatItem*) lParam);
handled = true;
break;
case MSG_HAS_DIALOG:
// Set to true if you provide a gui
handled = false;
break;
case MSG_DO_DIALOG:
// This isn't called unless you return true to MSG_HAS_DIALOG
doDialog((QWidget*) wParam, (QWidget**) lParam);
break;
case MSG_END_DIALOG:
// This isn't called unless you return true to MSG_HAS_DIALOG
endDialog((bool) wParam);
break;

还有一些迷信活动

至今没理解是为什么,看下面的代码:

void mypluginPlugin::getLabels(QList<InputData>* id)
{
//此处省略一段代码...
if (id->first().hasLabel(HASH_myplugin))
{
id->first().setTopResult(CatItem("", id->last().getText(), HASH_myplugin, getIcon()));
}
}

加了这一段代码之后,就只出现跟插件有关的结果项,如果没有这一段代码,就会杂七杂八出现很多。所以我说InputData的top result很关键。

调试工具

因为我们是插件开发,没法在线调试,只能用qDebug()<<"proxy: "<<proxy;打印调试语句。又没有命令行界面,只能借助一个微软的工具叫DebugView,在下面的地址下载。DebugView官方下载地址
有了他就可以看调试信息输出了。

QT相关

QT调用python

其实就是C++调用python。网上搜到的一堆都大同小异。举个例子QT中 使用c++调用python。最后我失败了,编译成功,运行失败。原因,我总结了一下,其实和QT以及VS搭配使用时版本的问题类似。C++调用python的接口函数都是在python27.lib中定义的。这个lib使用的编译平台,要和你现在使用的编译平台一致。不过看起来蛮诱人的,不过不知道有多少可能能用得上。

QProcess

放弃python27.lib之后,就转到QProcess上来了。这个其实就是QT简单的调用命令行程序。但是这个变态的是一旦命令出错,什么信息也打不出来,别看他有readStandardError接口。在使用QProcess的时候,学习到以下几点:

  1. Windows底下在代码里要用中文必须在字符串前面加L,如L"有道翻译"。这样Windows才能识别到这个是WCHAR,Windows平台的双字节编码
  2. QT里面所有的QString都是unicode,如QString::fromWCharArray(L"有道翻译)

QJson

本来打算找一个库来解析有道API返回的json数据,不过后来本着小而美的精神,放弃了解析整个json数据的企图,只单纯的解析多行字符串。不过还是看了一些资料,所以记下来万一以后用得上。
QJson是一个QT的开源库,在git hub上,需要下载源码自己编译。编出来会有一个.lib和一个.dll。分别放到C:\Qt\4.6.0\lib和C:\Qt\4.6.0\bin\底下,并在.pro文件里引用就可以用了。记得哦,与你的主程序用同一个编译平台。另外QT5已经默认内置json解析库了。
使用QJson的方法看官方文档
另外一种解析json数据的思路是用QT4内置的QScriptEngine。没深究过,但知道这个库是让QT更好地和JavaScript融合使用诞生的,具体可以看这个链接-QScriptEngine Printout to String as JSON

一些有用的链接

%23Launchy%u6709%u9053%u7FFB%u8BD1%u63D2%u4EF6%u5F00%u53D1%0A@%28%u5DE5%u4F5C%u7B14%u8BB0%29%5BQT%5D%0A%u4E00%u76F4%u60F3%u505A%u4E00%u4E2A%u65B9%u4FBF%u67E5%u8BCD%u7684%u5DE5%u5177%u3002%u4E00%u5F00%u59CB%u60F3%u501F%u52A9OSX%u4E0B%u9762%u6700%u706B%u7684Alfred%uFF0C%u505A%u4E00%u4E2A%u63D2%u4EF6%u3002%u7ED3%u679C%u4EE5%u4E3A%u8D5A%u4FBF%u5B9C%u6DD8%u5B9D%u4E0A50%u5757%u94B1%u4E70%u4E86%u4E00%u4E2Afamily%20license%uFF0C%u7ED3%u679C%u88AB%u65E0%u826F%u5978%u5546%u9A97%u4E86%u3002license%u6CA1%u51E0%u5929%u5C31%u5931%u6548%u4E86%uFF0C%u6295%u8BC9%u65E0%u95E8%u3002%u540E%u6765%u53D1%u73B0%u4E00%u76F4%u5728%u7528%u7684Windows%u5FEB%u6377%u65B9%u5F0F%u795E%u5668Launchy%uFF0C%u4E5F%u652F%u6301%u63D2%u4EF6%u5F00%u53D1%u3002%u4E8E%u662F%uFF0C%u9501%u5B9A%u76EE%u6807%uFF0C%u505A%u4E00%u4E2ALaunchy%u7684%u6709%u9053%u63D2%u4EF6%u3002%0A%u9996%u5148%u770B%5BLaunchy%u63D2%u4EF6%u5F00%u53D1%u5B98%u65B9%u9875%5D%28http%3A//www.launchy.net/api2.0/%29%u3002%u4EBA%u5BB6%u5199%u6E05%u695A%u4E86%u73AF%u5883%u7684%u7248%u672C%u8981%u6C42%uFF1A%0A%3EFor%20this%20setup%2C%20we%20require%20**Visual%20Studio%20%28preferably%202005**%20as%20that%20is%20what%20I%20use%29%20and%20**QT%204.3.3**%0A%0A%u540E%u6765%u5C31%u56E0%u4E3A%u7248%u672C%u95EE%u9898%u8D70%u4E86%u5F88%u591A%u5F2F%u8DEF%u3002%0A%23%23%u529F%u80FD%u6982%u8FF0%0A1.%20%u5FEB%u901F%u8FDB%u5165%u63D2%u4EF6%20-%20yd%26lt%3Btab%26gt%3B%0A2.%20%u4ECE%u526A%u8D34%u677F%u53D6%u5355%u8BCD%uFF0C%u6216%u81EA%u884C%u8F93%u5165%0A%21%5BAlt%20text%5D%28./1469437387713.png%29%0A%21%5BAlt%20text%5D%28./1469437454898.png%29%0A3.%20%u67E5%u5355%u8BCD%20-%20%26lt%3Btab%26gt%3B%0A%20%21%5BAlt%20text%5D%28./1469437302454.png%29%0A4.%20%u6267%u884C%u4EFB%u610F%u7ED3%u679C%u9879%u5747%u6253%u5F00%u5355%u8BCD%u7684%u6709%u9053%u8BCD%u5178%u9875%u9762%0A%21%5BAlt%20text%5D%28./1469437529508.png%29%0A%0A%23%23QT%u73AF%u5883%u5B89%u88C5%0A%23%23%23QT4%20vs.QT5%0A%u76EE%u524DQT%u7684%u6700%u65B0%u7248%u672C%u662F5.6%uFF0C%u6240%u4EE5%u76F4%u63A5%u8D70%u5B98%u65B9%u7528%u7F51%u7EDC%u5B89%u88C5%u7684%u90FD%u662FQT5%u3002%u6240%u4EE5%u4E00%u5F00%u59CB%uFF0C%u50BB%u4E4E%u4E4E%u7684%u51C6%u5907%u628A%u539F%u5148%u7684%u63D2%u4EF6%u6846%u67B6%u5199%u6210QT5%u517C%u5BB9%u3002QT4%u5230QT5%u505A%u4E86%u5927%u89C4%u6A21%u7684%u53D8%u5316%uFF0C%u5F88%u591A%u7279%u6027%u4E0D%u517C%u5BB9%u3002%u4E0B%u9762%u662F%u4E00%u4E9B%u53C2%u8003%u94FE%u63A5%0A*%20%5B%u5B98%u65B9%u6307%u5F15%5D%28http%3A//wiki.qt.io/Transition_from_Qt_4.x_to_Qt5%29%0A*%20%5BQ_EXPORT_PLUGIN2%20to%20Q_PLUGIN_METADATA%5D%28http%3A//osdir.com/ml/kde-commits/2015-03/msg07583.html%29%0A%u603B%u4E4B%u6363%u9F13%u4E86%u5F88%u4E45%uFF0C%u6700%u7EC8%u653E%u5F03%u3002%0A%23%23%23QT%u5B89%u88C5%0AQT%u6709%u591A%u79CD%u5B89%u88C5%u65B9%u5F0F%uFF1A%0A1.%20%u6700%u7B80%u5355%u7684%u5C31%u662F%5B%u5B98%u7F51%5D%28https%3A//www.qt.io/download/%29%uFF0C%u901A%u8FC7%u7F51%u7EDC%u65B9%u5F0F%u5B89%u88C5%uFF0C%u6CE8%u610F%u9009community%u548Copen%20source%u3002%u5176%u4ED6%u662F%u8981license%20fee%u7684%0A2.%20exe%u5B89%u88C5%u3002%u4EE5%5B4.8.6%5D%28https%3A//download.qt.io/archive/qt/4.8/4.8.6/%29%u4E3A%u4F8B%uFF0C%u5728QT%20archive%u7684%u7F51%u7AD9%u4E0A%u53EF%u4EE5%u4E0B%u8F7D%u5B98%u65B9%u7528%u5404%u79CD%u7F16%u8BD1%u5668%u7F16%u597D%u7684%u4E8C%u8FDB%u5236%u5B89%u88C5%u5305%u3002%0A%21%5BAlt%20text%5D%28./1469352211795.png%29%0A3.%20%u6700%u7075%u6D3B%u7684%u5B89%u88C5%u65B9%u5F0F%u5C31%u662F%u7F16%u8BD1%u5B89%u88C5%u4E86%u3002%u53BB%u4E0A%u9762archive%u7684%u7F51%u7AD9%u4E0B%u8F7D%5B%u6E90%u7801%5D%28https%3A//download.qt.io/archive/qt/4.8/4.8.6/qt-everywhere-opensource-src-4.8.6.zip%29%u3002%u597D%u5904%u662F%u53EF%u4EE5%u7F16%u8BD1%u51FA%u81EA%u5DF1%u9700%u8981%u7684%u7F16%u8BD1%u5668%u7684%u7248%u672C%u3002%u5177%u4F53%u652F%u6301%u54EA%u4E9B%u7F16%u8BD1%u5E73%u53F0%u770B%u6E90%u7801%u76EE%u5F55%60%3CQt%3E%5C4.6.0%5Cmkspecs%5C%60%uFF0C%u4E0B%u9762%u5217%u51FA%u4E86%u6240%u6709%u652F%u6301%u7684%u5F00%u53D1%u5E73%u53F0%u3002%0A%0A%0A%u6709%u4E00%u70B9%u5F88%u6709%u610F%u601D%u7684%u662F%uFF0C%u5728%u6211%u6298%u817EQT5%u7684%u65F6%u5019%u53D1%u73B0%uFF0CQT5%u76EE%u524D%u8FD8%u4E0D%u652F%u6301VS2015%u7684%u7F16%u8BD1%u5E73%u53F0%uFF0C%u6700%u9AD8%u53EA%u652F%u6301%u5230VS2013%u3002%0A%u56DE%u5230%u6211%u4EEC%u7684%u9700%u6C42%u4E0A%uFF0C%u53EF%u4EE5%u770B%u5230%uFF0C%u6309%u7167Launchy%u5B98%u65B9%u7684%u6307%u70B9%uFF0C%u6211%u4EEC%u9700%u8981VS2005%uFF0C%u4EE5%u53CA%u5BF9%u5E94%u7684QT%u5E93%uFF0C%u6240%u4EE5archive%u9875%u4E0A%u4E5F%u6CA1%u6709%u73B0%u6210%u7684%u4E8C%u8FDB%u5236%u5B89%u88C5%u5305%uFF0C%u53EA%u597D%u81EA%u5DF1%u7F16%u8BD1%u3002%u4F9D%u7136%u6709%5B%u5B98%u65B9%u6307%u5F15%5D%28http%3A//doc.qt.io/qt-4.8/install-win.html%29%u3002%u5176%u5B9E%u5F88%u5BB9%u6613%uFF0C%u6240%u8C13%u4F1A%u8005%u4E0D%u96BE%u3002%u6709%u51E0%u4E2A%u5730%u65B9%u8981%u6CE8%u610F%uFF1A%0A1.%20%u4E0B%u8F7DVS2005%u7684%u65F6%u5019%u4E00%u5B9A%u8981%u627E%u9760%u8C31%u7684%u5B89%u88C5%uFF0C%u5426%u5219%u50CF%u6211%u4E00%u5F00%u59CB%u88C5%u7684%u662F%u4E2A%u7E41%u4E2D%u7248%u672C%uFF0C%u5404%u79CD%u9519%u8BEF%uFF0C%u8BA9%u4EBA%u5F88%u662F%u90C1%u95F7%u3002%0A2.%20%u4E00%u5B9A%u8981%u4ECEVS%u7684command%20prompt%u8FDB%u53BBconfigue%u548Ccompile%u3002%u56E0%u4E3AVS%u7684command%20prompt%u4F1A%u505A%u5F88%u591A%u73AF%u5883%u914D%u7F6E%u3002%0A3.%20x86%u548Cx64%u662F%u4E0D%u540C%u7684command%20prompt%0A%0A%u5269%u4E0B%u6765%u7684%u6309%u7167%u5B98%u65B9%u7684%u6307%u5F15%u5C31%u53EF%u4EE5%u4E86%uFF0C%u7B80%u5355%u770B%u5982%u4E0B%uFF1A%0A%60%60%60%0Aconfigure%20-platform%20win32-msvc2005%0Anmake%0A%60%60%60%0A%23%23%23QT%u5F00%u53D1%u73AF%u5883%0A%u5B98%u7F51%u5B89%u88C5%u7684%u7248%u672C%u81EA%u5E26%u4E86QT%20Creator%u3002%u6240%u4EE5%u4E00%u5F00%u59CB%u90FD%u662F%u7528%u4ED6%u5728%u6298%u817E%uFF0C%u611F%u89C9%u7528%u8D77%u6765%u8FD8%u4E0D%u9519%uFF0C%u6CA1%u6709VS%u90A3%u4E48%u81C3%u80BF%u3002%u6362%u5230QT4.8.6%u4EE5%u540E%uFF0C%u53EF%u80FD%u7248%u672C%u8FC7%u4F4E%uFF0C%u5F00%u4E0D%u8D77%u6765%uFF0C%u6240%u4EE5%u6CA1%u529E%u6CD5%u8981%u5207%u5230VS2005%u5E95%u4E0B%u5F00%u53D1%u3002%u7136%u540E%u53C8%u6478%u7D22%u4E86%u4E00%u9635%uFF0C%u9700%u8981%u5B89%u88C5%u4E00%u4E2AVS%u7684QT%u63D2%u4EF6%u3002%u540E%u6765%u53C8%u662F%u5728%u7248%u672C%u4E0A%u4E00%u756A%u6298%u817E%uFF0C%u6700%u7EC8%u9009%u5B9A%5B1.1.11%5D%28https%3A//download.qt.io/official_releases/vsaddin/%29%uFF0C%u914D%u5408VS2005%u4F7F%u7528%u65E0%u538B%u529B%u3002%0A%0A%23%23Launchy%u63D2%u4EF6%u5F00%u53D1%0A%u5176%u5B9E%u5F88%u7B80%u5355%uFF0C%u6309%u7167%u4F5C%u8005%u7684%u63A8%u8350%uFF0C%u7248%u672C%u4E00%u6B65%u4E0D%u5DEE%uFF0C%u6216%u8005%u5DEE%u7684%u4E0D%u8FDC%uFF0C%u90FD%u662F%u53EF%u4EE5%u8DD1%u8D77%u6765%u7684%u3002%u6700%u7EC8%u7248%u672C**VS2005+QT4.6.0+qt-vs-1.1.11**%u3002%0A%u4E2D%u95F4%u8BD5%u8FC7VS2013%uFF0C%u5982%u679C%u6574%u4E2ALaunchy%u75282013%u7F16%u8BD1%uFF0C%u63D2%u4EF6%u4E5F%u75282013%u7F16%u8BD1%u7684%u8BDD%uFF0C%u662F%u53EF%u4EE5%u7528%u7684%u3002%u4F46%u662F%u8FD9%u6837%u79FB%u690D%u6027%u592A%u5DEE%u4E86%uFF0C%u7F51%u4E0A%u4E0B%u8F7D%u7684Launchy%u5C31%u6CA1%u6CD5%u7528%u4E86%u3002%0A%23%23%23Launchy%u63D2%u4EF6%0A%u7B80%u5355%u8BF4%u4E00%u4E0BLaunchy%u7684%u63D2%u4EF6%u7ED3%u6784%uFF0C%u4EE5%u4FBF%u672A%u6765%u5982%u679C%u8981%u8FDB%u4E00%u6B65%u5F00%u53D1%u53C8%u5F97%u91CD%u65B0%u5B66%u4E60%uFF1A%0A%23%23%23%23%u63D2%u4EF6%u57FA%u4E8E%u6D88%u606F%u5DE5%u4F5C%0A%60%60%60%09%0A%09%09case%20MSG_INIT%3A%0A%09init%28%29%3B%0A%09handled%20%3D%20true%3B%0A%09break%3B%0Acase%20MSG_GET_LABELS%3A%20//%20%u6BCF%u4E2Ainput%u53EF%u4EE5%u6253label%uFF0C%u4EE5%u540E%u53EF%u4EE5%u6839%u636Elabel%u6765%u7504%u522B%u5C5E%u4E8E%u54EA%u4E2A%u63D2%u4EF6%0A%09getLabels%28%28QList%3CInputData%3E*%29%20wParam%29%3B%0A%09handled%20%3D%20true%3B%0A%09break%3B%0Acase%20MSG_GET_ID%3A%0A%09getID%28%28uint*%29%20wParam%29%3B%0A%09handled%20%3D%20true%3B%0A%09break%3B%0Acase%20MSG_GET_NAME%3A%0A%09getName%28%28QString*%29%20wParam%29%3B%0A%09handled%20%3D%20true%3B%0A%09break%3B%0Acase%20MSG_GET_RESULTS%3A//%20%u5728%u8FD9%u91CC%u4E3A%u8F93%u5165%u63D2%u5165%u7ED3%u679C%0A%09getResults%28%28QList%3CInputData%3E*%29%20wParam%2C%20%28QList%3CCatItem%3E*%29%20lParam%29%3B%0A%09handled%20%3D%20true%3B%0A%09break%3B%0Acase%20MSG_GET_CATALOG%3A%20//%20catalog%u662FLaunchy%u7684%u6570%u636E%u5E93%u5165%u53E3%u3002%u5BF9%u4E8E%u63D2%u4EF6%u6570%u636E%u91CF%u4E0D%u5927%u7684%u8BDD%uFF0C%u53EF%u4EE5%u5FFD%u7565%u8FD9%u4E2A%0A%09getCatalog%28%28QList%3CCatItem%3E*%29%20wParam%29%3B%0A%09handled%20%3D%20true%3B%0A%09break%3B%0Acase%20MSG_LAUNCH_ITEM%3A%20//%20%u6FC0%u53D1%u67D0%u4E2A%u7ED3%u679C%u9879%uFF0C%u8FD9%u91CC%u8981%u6CE8%u610FInputData%u7684top%20result%0A%09//qDebug%28%29%3C%3C%22Launch%22%3B%0A%09launchItem%28%28QList%3CInputData%3E*%29%20wParam%2C%20%28CatItem*%29%20lParam%29%3B%0A%09handled%20%3D%20true%3B%0A%09break%3B%0Acase%20MSG_HAS_DIALOG%3A%0A%09//%20Set%20to%20true%20if%20you%20provide%20a%20gui%0A%09handled%20%3D%20false%3B%0A%09break%3B%0Acase%20MSG_DO_DIALOG%3A%0A%09//%20This%20isn%27t%20called%20unless%20you%20return%20true%20to%20MSG_HAS_DIALOG%0A%09doDialog%28%28QWidget*%29%20wParam%2C%20%28QWidget**%29%20lParam%29%3B%0A%09break%3B%0Acase%20MSG_END_DIALOG%3A%0A%09//%20This%20isn%27t%20called%20unless%20you%20return%20true%20to%20MSG_HAS_DIALOG%0A%09endDialog%28%28bool%29%20wParam%29%3B%0A%09break%3B%0A%60%60%60%0A%0A%23%23%23%23%u8FD8%u6709%u4E00%u4E9B%u8FF7%u4FE1%u6D3B%u52A8%0A%u81F3%u4ECA%u6CA1%u7406%u89E3%u662F%u4E3A%u4EC0%u4E48%uFF0C%u770B%u4E0B%u9762%u7684%u4EE3%u7801%uFF1A%0A%60%60%60%0Avoid%20mypluginPlugin%3A%3AgetLabels%28QList%3CInputData%3E*%20id%29%0A%7B%0A%09//%u6B64%u5904%u7701%u7565%u4E00%u6BB5%u4EE3%u7801...%0A%09if%20%28id-%3Efirst%28%29.hasLabel%28HASH_myplugin%29%29%0A%09%7B%0A%09%09id-%3Efirst%28%29.setTopResult%28CatItem%28%22%22%2C%20id-%3Elast%28%29.getText%28%29%2C%20HASH_myplugin%2C%20getIcon%28%29%29%29%3B%0A%09%7D%0A%7D%0A%60%60%60%0A%u52A0%u4E86%u8FD9%u4E00%u6BB5%u4EE3%u7801%u4E4B%u540E%uFF0C%u5C31%u53EA%u51FA%u73B0%u8DDF%u63D2%u4EF6%u6709%u5173%u7684%u7ED3%u679C%u9879%uFF0C%u5982%u679C%u6CA1%u6709%u8FD9%u4E00%u6BB5%u4EE3%u7801%uFF0C%u5C31%u4F1A%u6742%u4E03%u6742%u516B%u51FA%u73B0%u5F88%u591A%u3002%u6240%u4EE5%u6211%u8BF4InputData%u7684top%20result%u5F88%u5173%u952E%u3002%0A%21%5BAlt%20text%5D%28./1469435667177.png%29%0A%23%23%23%23%u8C03%u8BD5%u5DE5%u5177%0A%u56E0%u4E3A%u6211%u4EEC%u662F%u63D2%u4EF6%u5F00%u53D1%uFF0C%u6CA1%u6CD5%u5728%u7EBF%u8C03%u8BD5%uFF0C%u53EA%u80FD%u7528%60qDebug%28%29%3C%3C%22proxy%3A%20%22%3C%3Cproxy%3B%60%u6253%u5370%u8C03%u8BD5%u8BED%u53E5%u3002%u53C8%u6CA1%u6709%u547D%u4EE4%u884C%u754C%u9762%uFF0C%u53EA%u80FD%u501F%u52A9%u4E00%u4E2A%u5FAE%u8F6F%u7684%u5DE5%u5177%u53EBDebugView%uFF0C%u5728%u4E0B%u9762%u7684%u5730%u5740%u4E0B%u8F7D%u3002%5BDebugView%u5B98%u65B9%u4E0B%u8F7D%u5730%u5740%5D%28https%3A//technet.microsoft.com/en-us/sysinternals/debugview.aspx%29%u3002%0A%u6709%u4E86%u4ED6%u5C31%u53EF%u4EE5%u770B%u8C03%u8BD5%u4FE1%u606F%u8F93%u51FA%u4E86%u3002%0A%23%23%23QT%u76F8%u5173%0A%23%23%23%23QT%u8C03%u7528python%0A%u5176%u5B9E%u5C31%u662FC++%u8C03%u7528python%u3002%u7F51%u4E0A%u641C%u5230%u7684%u4E00%u5806%u90FD%u5927%u540C%u5C0F%u5F02%u3002%u4E3E%u4E2A%u4F8B%u5B50%5BQT%u4E2D%20%u4F7F%u7528c++%u8C03%u7528python%5D%28http%3A//www.cnblogs.com/shenghl/p/4442528.html%29%u3002%u6700%u540E%u6211%u5931%u8D25%u4E86%uFF0C%u7F16%u8BD1%u6210%u529F%uFF0C%u8FD0%u884C%u5931%u8D25%u3002%u539F%u56E0%uFF0C%u6211%u603B%u7ED3%u4E86%u4E00%u4E0B%uFF0C%u5176%u5B9E%u548CQT%u4EE5%u53CAVS%u642D%u914D%u4F7F%u7528%u65F6%u7248%u672C%u7684%u95EE%u9898%u7C7B%u4F3C%u3002C++%u8C03%u7528python%u7684%u63A5%u53E3%u51FD%u6570%u90FD%u662F%u5728python27.lib%u4E2D%u5B9A%u4E49%u7684%u3002%u8FD9%u4E2Alib%u4F7F%u7528%u7684%u7F16%u8BD1%u5E73%u53F0%uFF0C%u8981%u548C%u4F60%u73B0%u5728%u4F7F%u7528%u7684%u7F16%u8BD1%u5E73%u53F0%u4E00%u81F4%u3002%u4E0D%u8FC7%u770B%u8D77%u6765%u86EE%u8BF1%u4EBA%u7684%uFF0C%u4E0D%u8FC7%u4E0D%u77E5%u9053%u6709%u591A%u5C11%u53EF%u80FD%u80FD%u7528%u5F97%u4E0A%u3002%0A%23%23%23%23QProcess%0A%u653E%u5F03python27.lib%u4E4B%u540E%uFF0C%u5C31%u8F6C%u5230QProcess%u4E0A%u6765%u4E86%u3002%u8FD9%u4E2A%u5176%u5B9E%u5C31%u662FQT%u7B80%u5355%u7684%u8C03%u7528%u547D%u4EE4%u884C%u7A0B%u5E8F%u3002%u4F46%u662F%u8FD9%u4E2A%u53D8%u6001%u7684%u662F%u4E00%u65E6%u547D%u4EE4%u51FA%u9519%uFF0C%u4EC0%u4E48%u4FE1%u606F%u4E5F%u6253%u4E0D%u51FA%u6765%uFF0C%u522B%u770B%u4ED6%u6709readStandardError%u63A5%u53E3%u3002%u5728%u4F7F%u7528QProcess%u7684%u65F6%u5019%uFF0C%u5B66%u4E60%u5230%u4EE5%u4E0B%u51E0%u70B9%uFF1A%0A1.%20Windows%u5E95%u4E0B%u5728%u4EE3%u7801%u91CC%u8981%u7528%u4E2D%u6587%u5FC5%u987B%u5728%u5B57%u7B26%u4E32%u524D%u9762%u52A0L%uFF0C%u5982%60L%22%u6709%u9053%u7FFB%u8BD1%22%60%u3002%u8FD9%u6837Windows%u624D%u80FD%u8BC6%u522B%u5230%u8FD9%u4E2A%u662FWCHAR%uFF0CWindows%u5E73%u53F0%u7684%u53CC%u5B57%u8282%u7F16%u7801%0A2.%20QT%u91CC%u9762%u6240%u6709%u7684QString%u90FD%u662Funicode%uFF0C%u5982%60QString%3A%3AfromWCharArray%28L%22%u6709%u9053%u7FFB%u8BD1%29%60%0A%23%23%23%23QJson%0A%u672C%u6765%u6253%u7B97%u627E%u4E00%u4E2A%u5E93%u6765%u89E3%u6790%u6709%u9053API%u8FD4%u56DE%u7684json%u6570%u636E%uFF0C%u4E0D%u8FC7%u540E%u6765%u672C%u7740%u5C0F%u800C%u7F8E%u7684%u7CBE%u795E%uFF0C%u653E%u5F03%u4E86%u89E3%u6790%u6574%u4E2Ajson%u6570%u636E%u7684%u4F01%u56FE%uFF0C%u53EA%u5355%u7EAF%u7684%u89E3%u6790%u591A%u884C%u5B57%u7B26%u4E32%u3002%u4E0D%u8FC7%u8FD8%u662F%u770B%u4E86%u4E00%u4E9B%u8D44%u6599%uFF0C%u6240%u4EE5%u8BB0%u4E0B%u6765%u4E07%u4E00%u4EE5%u540E%u7528%u5F97%u4E0A%u3002%0A%5BQJson%5D%28https%3A//github.com/flavio/qjson%29%u662F%u4E00%u4E2AQT%u7684%u5F00%u6E90%u5E93%uFF0C%u5728git%20hub%u4E0A%uFF0C%u9700%u8981%u4E0B%u8F7D%u6E90%u7801%u81EA%u5DF1%u7F16%u8BD1%u3002%u7F16%u51FA%u6765%u4F1A%u6709%u4E00%u4E2A.lib%u548C%u4E00%u4E2A.dll%u3002%u5206%u522B%u653E%u5230C%3A%5CQt%5C4.6.0%5Clib%u548CC%3A%5CQt%5C4.6.0%5Cbin%5C%u5E95%u4E0B%uFF0C%u5E76%u5728.pro%u6587%u4EF6%u91CC%u5F15%u7528%u5C31%u53EF%u4EE5%u7528%u4E86%u3002%u8BB0%u5F97%u54E6%uFF0C%u4E0E%u4F60%u7684%u4E3B%u7A0B%u5E8F%u7528%u540C%u4E00%u4E2A%u7F16%u8BD1%u5E73%u53F0%u3002%u53E6%u5916QT5%u5DF2%u7ECF%u9ED8%u8BA4%u5185%u7F6Ejson%u89E3%u6790%u5E93%u4E86%u3002%0A%u4F7F%u7528QJson%u7684%u65B9%u6CD5%u770B%5B%u5B98%u65B9%u6587%u6863%5D%28http%3A//qjson.sourceforge.net/docs/%29%0A%u53E6%u5916%u4E00%u79CD%u89E3%u6790json%u6570%u636E%u7684%u601D%u8DEF%u662F%u7528QT4%u5185%u7F6E%u7684QScriptEngine%u3002%u6CA1%u6DF1%u7A76%u8FC7%uFF0C%u4F46%u77E5%u9053%u8FD9%u4E2A%u5E93%u662F%u8BA9QT%u66F4%u597D%u5730%u548CJavaScript%u878D%u5408%u4F7F%u7528%u8BDE%u751F%u7684%uFF0C%u5177%u4F53%u53EF%u4EE5%u770B%u8FD9%u4E2A%u94FE%u63A5-%5BQScriptEngine%20Printout%20to%20String%20as%20JSON%5D%28http%3A//www.qtcentre.org/threads/30874-QScriptEngine-Printout-to-String-as-JSON%29%0A%23%23%23%u4E00%u4E9B%u6709%u7528%u7684%u94FE%u63A5%0A-%20%5B%u5728%u7EBF%u7F16%u7801%u89E3%u7801%5D%28http%3A//bianma.911cha.com/%29%0A-%20%5BJS/HTML%u683C%u5F0F%u5316%5D%28http%3A//tool.chinaz.com/Tools/jsformat.aspx%3Fjdfwkey%3Dwslz01%29%0A%0A