0

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

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

经过数小时的阅读文档和尝试各种事情后,我仍然找不到在本地使用自定义键盘的方法,而不删除原始的“qtvirtualkeyboardplugin.dll”。

4

1 回答 1

0

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

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

以下是作为 Git diff 的更改:

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

请记住,如果您使用的是开源许可证,则必须对应用程序用户可用的 Qt 代码进行修改

于 2017-03-30T10:41:11.517 回答