本文介绍了QML VirtualKeyboard错误,以输入网站的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我目前正在修复目录系统上的一些错误。 这个系统有一个Webview面板和一个虚拟键盘。 这个系统是用QML,Javascript开发的和1%的C ++。 虚拟键盘在代码中有错误。 我输入了小写字母a,在网站文本框中它将显示为大写A。这发生在从A到Z的所有角色。 另一个问题是当我进入符号时,会出现奇怪的角色在文本框中。 以下来自事件面板的来源 QML 文件。 I currently repairing some bugs on the Directory System.This system has a Webview panel and also a virtual keyboard.This system was developed by using QML, Javascript and 1% of C++.The virtual keyboard has error in the codes. I entered lower case ''a'',in the website textbox it will appear as upper-case''A''. And this happen to all the character from A to Z.And another problem is when I entered Symbols, there will be weird character appearing in the textbox.Here below source from Event Panel QML file.//------------------------------------------------------// Keyboard//------------------------------------------------------WebKeyboardPad{ id: keyboard x: 0 y: event_panel.height + keyboard.height; anchors.horizontalCenter: parent.horizontalCenter onClicked: Globals.onKeyboardClicked(tag); onBackspace: Globals.onKeyboardBackspace(); opacity: 1 Behavior on y { id: behavior_nb_keyboard_y enabled: keyboard.isDragging NumberAnimation { duration: 300; } } Behavior on opacity { NumberAnimation { duration: 300; } }} 此来源来自 JavaScript 文件; This source is from a JavaScript file;function onKeyboardClicked(keyName){ home_main.onKeyboardClicked(keyName);}function onKeyboardBackspace(){ home_main.onKeyboardClicked("backspace");} 来自Main QML 文件 This from Main QML file//--------------------------------------------------- // Custom plugins //--------------------------------------------------- HardwareInfo { id: syshardware } function onKeyboardClicked(Keys) { myKeyboard.simulateKey(Keys); //Injected in main.cpp } function onKeyboardBackspace(KeyNavigation) { myKeyboard.simulateKey(KeyNavigation); //Injected in main.cpp //search_box.backspaceKey(); } 这里最后一个是C ++文件 keyboard.cpp 我更改了 keyboard.cpp 文件,但是当我尝试更改c ++代码时,结果仍然相同。 Here the last one is the C++ filekeyboard.cppI got change the keyboard.cpp file but when I try which the c++ code change, the result still the same.#include "keyboard.h"#include <qevent>#include <qkeyevent>#include <qapplication>Keyboard::Keyboard(QObject *parent) : QObject(parent){ theWidget = NULL;}void Keyboard::setWidget(QWidget* theWidget){ this->theWidget = theWidget;}void Keyboard::simulateKey(QString keyName){ Qt::Key keycode = getKeyCodeFromName(keyName); if (keycode == Qt::Key_unknown || this->theWidget == NULL) return; //A-Z if (keyName.length() == 1 && keyName[0].unicode() >= 'A' && keyName[0].unicode() <= 'Z') { QKeyEvent keyPressEvent(QEvent::KeyPress, keycode, Qt::ShiftModifier); QApplication::sendEvent(this->theWidget, &keyPressEvent); QKeyEvent keyReleaseEvent(QEvent::KeyRelease, keycode, Qt::ShiftModifier); QApplication::sendEvent(this->theWidget, &keyReleaseEvent); } else { QKeyEvent keyPressEvent(QEvent::KeyPress, keycode, Qt::NoModifier); QApplication::sendEvent(this->theWidget, &keyPressEvent); QKeyEvent keyReleaseEvent(QEvent::KeyRelease, keycode, Qt::NoModifier); QApplication::sendEvent(this->theWidget, &keyReleaseEvent); } qDebug("Simulating key: %s", qPrintable(keyName));}Qt::Key Keyboard::getKeyCodeFromName(QString keyname){ keyname = keyname.toLower(); if (keyname.length() < 1) return Qt::Key_unknown; if (keyname == "left") return Qt::Key_Left; else if (keyname == "right") return Qt::Key_Right; else if (keyname == "up") return Qt::Key_Up; else if (keyname == "down") return Qt::Key_Down; else if (keyname == "center") return Qt::Key_Enter; else if (keyname == "enter") return Qt::Key_Enter; else if (keyname == "tab") return Qt::Key_Tab; else if (keyname == "\n") return Qt::Key_Enter; else if (keyname == "cpanel") return Qt::Key_PageUp; else if (keyname == "widget") return Qt::Key_PageDown; else if (keyname == "pgup") return Qt::Key_PageUp; else if (keyname == "pgdown") return Qt::Key_PageDown; else if (keyname == "pageup") return Qt::Key_PageUp; else if (keyname == "pagedown") return Qt::Key_PageDown; else if (keyname == "esc") return Qt::Key_Escape; else if (keyname == "del") return Qt::Key_Delete; else if (keyname == "delete") return Qt::Key_Delete; else if (keyname == "backspace") return Qt::Key_Backspace; else if (keyname == "space") return Qt::Key_Space; else if (keyname == " ") return Qt::Key_Space; else if (keyname == "+") return Qt::Key_Plus; else if (keyname == "-") return Qt::Key_Minus; else if (keyname == "*") return Qt::Key_Asterisk; else if (keyname == "/") return Qt::Key_Slash; else if (keyname == "\\") return Qt::Key_Backslash; else if (keyname == ".") return Qt::Key_Period; else if (keyname == ",") return Qt::Key_Comma; else if (keyname == "?") return Qt::Key_Question; else if (keyname == "<") return Qt::Key_Less; else if (keyname == ">") return Qt::Key_Greater; else if (keyname == "=") return Qt::Key_Equal; else if (keyname == "@") return Qt::Key_At; else if (keyname == "!") return Qt::Key_Exclam; else if (keyname == "%") return Qt::Key_Percent; else if (keyname == "$") return Qt::Key_Dollar; else if (keyname == ":") return Qt::Key_Colon; else if (keyname == ";") return Qt::Key_Semicolon; else if (keyname == "(") return Qt::Key_BracketLeft; else if (keyname == ")") return Qt::Key_BracketRight; else if (keyname == "{") return Qt::Key_BraceLeft; else if (keyname =&&&&= "}") return Qt::Key_BraceRight; else if (keyname == "\"") return Qt::Key_QuoteDbl; else if (keyname == "volup") return Qt::Key_VolumeUp; else if (keyname == "voldown") return Qt::Key_VolumeDown; else if (keyname == "mute") return Qt::Key_VolumeMute; else if (keyname == "search") return Qt::Key_Search; else if (keyname == "menu") return Qt::Key_Menu; else if (keyname.length() >= 2) { if (keyname.startsWith('f')) { bool convertOK = false; keyname = keyname.right(keyname.length()-1); int findex = keyname.toInt(&convertOK); if (convertOK) return (Qt::Key)(Qt::Key_F1 + (findex-1)); } } else { //a-z if (keyname[0].unicode() >= 'a' && keyname[0].unicode() <= 'z') return (Qt::Key)(Qt::Key_A + keyname[0].unicode() - 'a'); //A-Z if (keyname[0].unicode() >= 'A' && keyname[0].unicode() <= 'Z') return (Qt::Key)(Qt::Key_A + keyname[0].unicode() - 'A'); if (keyname[0].unicode() >= '0' && keyname[0].unicode() <= '9') return (Qt::Key)(Qt::Key_0 + keyname[0].unicode() - 'a'); } return Qt::Key_unknown;} keyboard.h keyboard.h#ifndef KEYBOARD_H#define KEYBOARD_H#include <QObject>#include <QWidget>class Keyboard : public QObject{ Q_OBJECTpublic: Keyboard(QObject *parent = NULL); void setWidget(QWidget*); Q_INVOKABLE void simulateKey(QString keyName);private: QWidget* theWidget; Qt::Key getKeyCodeFromName(QString keyname);};#endif // KEYBOARD_H 我已经更改了cpp文件,但它仍然无效。 希望有人可以帮我解决这个问题。 谢谢I have change the cpp file but it still does not work.Hopefully someone can help me to solve this problem.Thank you推荐答案 keyboard.h keyboard.h#ifndef KEYBOARD_H#define KEYBOARD_H#include <QObject>#include <QWidget>class Keyboard : public QObject{ Q_OBJECTpublic: Keyboard(QObject *parent = NULL); void setWidget(QWidget*); Q_INVOKABLE void simulateKey(QString keyName);private: QWidget* theWidget; Qt::Key getKeyCodeFromName(QString keyname);};#endif // KEYBOARD_H 我已经更改了cpp文件,但它仍然无效。 希望有人可以帮我解决这个问题。 谢谢I have change the cpp file but it still does not work.Hopefully someone can help me to solve this problem.Thank you 这篇关于QML VirtualKeyboard错误,以输入网站的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-12 13:55