QT5.8。自定义虚拟键盘​​包括

时间:2017-03-30 09:51:03

标签: qt qml qt5 qtvirtualkeyboard

我正在编写一个基于QtVirtualKeyboard的自定义虚拟键盘​​。对于我的项目,我需要能够使用我的键盘版本。

但我发现的唯一方法是重新编译项目并替换我的“qtvirtualkeyboardplugin.dll”版本中的“mingw53_32 \ plugins \ platforminputcontexts”中的原始“qtvirtualkeyboardplugin.dll”。并使用main.cpp中的qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));函数

经过几个小时阅读文档并尝试各种各样的事情后,我仍然无法找到使用自定义键盘localy的方法,而不删除原始的“qtvirtualkeyboardplugin.dll”。

1 个答案:

答案 0 :(得分:0)

我假设您已经分叉了代码,在这种情况下,以下修改似乎足以让不同名称的插件安装到plugins/platforminputcontexts

  • qtvirtualkeyboard/src/virtualkeyboard/qtvirtualkeyboard.json重命名为qtvirtualkeyboard/src/virtualkeyboard/customvirtualkeyboard.json
  • customvirtualkeyboard.json中,将qtvirtualkeyboard键重命名为customvirtualkeyboard
  • qtvirtualkeyboard/src/virtualkeyboard/plugin.cpp中,将pluginName字符串的内容更改为customvirtualkeyboard
  • qtvirtualkeyboard/src/virtualkeyboard/plugin.h中,将FILE字符串更改为customvirtualkeyboard
  • src/virtualkeyboard/virtualkeyboard.pro中,将TARGET = qtvirtualkeyboardplugin更改为TARGET = customvirtualkeyboardplugin。这会影响您在plugins/platforminputcontexts中看到的已安装.dll,.lib等的名称。

以下是Git差异的变化:

diff --git a/src/virtualkeyboard/customvirtualkeyboard.json b/src/virtualkeyboard/customvirtualkeyboard.json
new file mode 100644
index 0000000..9ef7a87
--- /dev/null
+++ b/src/virtualkeyboard/customvirtualkeyboard.json
@@ -0,0 +1,3 @@
+{
+    "Keys": [ "customvirtualkeyboard" ]
+}
diff --git a/src/virtualkeyboard/plugin.cpp b/src/virtualkeyboard/plugin.cpp
index 73ddeab..4abe9a4 100644
--- a/src/virtualkeyboard/plugin.cpp
+++ b/src/virtualkeyboard/plugin.cpp
@@ -76,7 +76,7 @@ using namespace QtVirtualKeyboard;

 Q_LOGGING_CATEGORY(qlcVirtualKeyboard, "qt.virtualkeyboard")

-static const char pluginName[] = "qtvirtualkeyboard";
+static const char pluginName[] = "customvirtualkeyboard";
 static const char inputMethodEnvVarName[] = "QT_IM_MODULE";
 static const char pluginUri[] = "QtQuick.VirtualKeyboard";
 static const char pluginSettingsUri[] = "QtQuick.VirtualKeyboard.Settings";
diff --git a/src/virtualkeyboard/plugin.h b/src/virtualkeyboard/plugin.h
index 08074d1..19593a4 100644
--- a/src/virtualkeyboard/plugin.h
+++ b/src/virtualkeyboard/plugin.h
@@ -38,7 +38,7 @@
 class QVirtualKeyboardPlugin : public QPlatformInputContextPlugin
 {
     Q_OBJECT
-    Q_PLUGIN_METADATA(IID QPlatformInputContextFactoryInterface_iid FILE "qtvirtualkeyboard.json")
+    Q_PLUGIN_METADATA(IID QPlatformInputContextFactoryInterface_iid FILE "customvirtualkeyboard.json")

 public:
     QStringList keys() const;
diff --git a/src/virtualkeyboard/qtvirtualkeyboard.json b/src/virtualkeyboard/qtvirtualkeyboard.json
deleted file mode 100644
index 76d1706..0000000
--- a/src/virtualkeyboard/qtvirtualkeyboard.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-    "Keys": [ "qtvirtualkeyboard" ]
-}
diff --git a/src/virtualkeyboard/virtualkeyboard.pro b/src/virtualkeyboard/virtualkeyboard.pro
index 4f3ca69..e9b0ff9 100644
--- a/src/virtualkeyboard/virtualkeyboard.pro
+++ b/src/virtualkeyboard/virtualkeyboard.pro
@@ -1,4 +1,4 @@
-TARGET  = qtvirtualkeyboardplugin
+TARGET  = customvirtualkeyboardplugin
 DATAPATH = $$[QT_INSTALL_DATA]/qtvirtualkeyboard

 QMAKE_DOCS = $$PWD/doc/qtvirtualkeyboard.qdocconf

请记住,如果您使用的是开源许可证you have to make modifications to Qt code available to users of your application