我制作了一个使用 qt 虚拟键盘的应用程序。我使用两种不同的编译器构建了它
- 使用 Qt Creator 4.14.2 附带的捆绑 mingw 编译器,使用 Qt 5.15.2
- 将mingw-w64-x86_64-qt5包与msys2一起使用,也是Qt 5.15.2
这是一个显示问题的简单可重现示例项目
。轮廓
QT += quick virtualkeyboard svg
CONFIG += c++11
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
main.cpp 文件:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
main.qml 文件:
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.VirtualKeyboard 2.15
ApplicationWindow {
id: window
visible: true
width: 640
height: 480
TextField {
anchors.centerIn: parent
}
InputPanel {
id: inputPanel
z: 89
y: active ? parent.height - height : parent.height
anchors.left: parent.left
anchors.right: parent.right
}
}
第一个编译并运行没有任何问题,如下所示:
第二个编译并运行如下:
唯一的区别是构建设置,其中一个选择了第一个工具链,而第二个选择了另一个。
msys2 工具链是我通常使用的工具链,它运行我使用的任何其他应用程序和库都没有任何问题。
我还添加了 QT_PLUGIN_DEBUG=1 并且可以验证所有库都已加载并在两个工具链中进行了说明。