You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Qt 6.8环境下CuteKeyboard虚拟键盘插件集成构建的报错排查与解决方案求助

Fixing CuteKeyboard Integration Issues with Qt 6.8.3 on Ubuntu 24.04

Let's break down the issues you're facing and walk through step-by-step fixes to get CuteKeyboard working properly with Qt 6.8.3.

1. Fix the QML Module Import & QQmlEngineExtensionInterface Error

The core problem here is that manually copying QML module files skips critical build steps that generate necessary metadata (like qmltypes files) and register the module correctly with Qt.

Correct Installation of the QML Module

Instead of manual file copying, let CMake handle deploying the module to your Qt 6.8.3 installation. Re-run the build with explicit Qt 6.8.3 paths to ensure it links against the correct version:

# Clean existing build artifacts
rm -rf ~/cutekeyboard/build

# Configure build with Qt 6.8.3 paths
cmake -S ~/cutekeyboard -B ~/cutekeyboard/build -GNinja \
  -DCMAKE_PREFIX_PATH=/opt/Qt/6.8.3/gcc_64 \
  -DQT_DIR=/opt/Qt/6.8.3/gcc_64/lib/cmake/Qt6 \
  -DCMAKE_INSTALL_PREFIX=/opt/Qt/6.8.3/gcc_64

# Build and install the module
cmake --build ~/cutekeyboard/build --target all
sudo cmake --install ~/cutekeyboard/build

This ensures:

  • The QML module is installed to the correct Qt 6.8.3 qml/QtQuick directory
  • Required files like cutekeyboardplugin.qmltypes are generated and deployed
  • The module is properly registered to avoid the QQmlEngineExtensionInterface error

2. Resolve the CMake Build Error for Examples (Qt 6.8.3)

The error with qt_generate_deploy_app_script occurs because CuteKeyboard's example CMakeLists uses older syntax incompatible with Qt 6.8. Fix it like this:

  1. Open ~/cutekeyboard/example/CMakeLists.txt in a text editor
  2. Locate this line block:
    qt_generate_deploy_app_script(
        TARGET example
        OUTPUT_SCRIPT deploy_script
        NO_UNSUPPORTED_PLATFORM_ERROR
    )
    
  3. Replace it with Qt 6.8-compatible syntax:
    qt_generate_deploy_app_script(
        TARGET example
        OUTPUT deploy_script
        NO_UNSUPPORTED_PLATFORM_ERROR
    )
    
    (Remove the OUTPUT_SCRIPT argument, use OUTPUT instead)
  4. Re-run the example build with Qt 6.8.3 paths:
    cmake -S ~/cutekeyboard -B ~/cutekeyboard/build -GNinja \
      -DCMAKE_PREFIX_PATH=/opt/Qt/6.8.3/gcc_64 \
      -DQT_DIR=/opt/Qt/6.8.3/gcc_64/lib/cmake/Qt6 \
      -DBUILD_EXAMPLES=ON
    cmake --build ~/cutekeyboard/build --target example
    

3. Fix the "Namespace Already Used" Error

This happens because you have duplicate installations of the CuteKeyboard module (system-wide and Qt 6.8-specific). Clean up and re-install properly:

  1. Remove the manually copied module:
    sudo rm -rf /opt/Qt/6.8.3/gcc_64/qml/QtQuick/CuteKeyboard
    
  2. Uninstall the system-wide installation:
    sudo cmake --build ~/cutekeyboard/build --target uninstall
    
  3. Re-install using the Qt 6.8.3-specific command from Section 1 above.

4. Verify Your Project Setup

After completing the fixes, double-check your project configuration:

  • In main.cpp, set QT_IM_MODULE before initializing the QML engine:
    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    int main(int argc, char *argv[])
    {
        qputenv("QT_IM_MODULE", QByteArray("cutekeyboard"));
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        const QUrl url(u"qrc:/qt/qml/qml_test/Main.qml"_qs);
        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();
    }
    
  • In Main.qml, ensure the import is correct and test with a focusable input:
    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.CuteKeyboard 1.0
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("CuteKeyboard Test")
    
        TextField {
            anchors.centerIn: parent
            width: 200
            // The virtual keyboard should auto-appear when this is focused
        }
    }
    
  • Run the project; the keyboard should pop up when the TextField gains focus.

Troubleshooting Tips

  • If the keyboard doesn't appear, check if the platform input context plugin loads correctly:
    QT_DEBUG_PLUGINS=1 ./your_app_executable
    
    Look for logs related to libcutekeyboardplugin.so to confirm successful loading.
  • Ensure your Qt project uses the Qt 6.8.3 kit in Qt Creator (check Kits > Qt Version).

内容的提问来源于stack exchange,提问作者user31684185

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 12:43:11