有人可以做一个简单的示例,将qtvirtualkeyboard模块包含到cmake文件中吗?我想访问这些类,但无法弄清楚如何包含它们。
答案 0 :(得分:0)
该示例应起作用。它是使用CMake 3.1.1和Qt 5.11.1编译的
The code在我的GitHub帐户中可用。 QML示例基于example provided by Qt。
主要CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
# 3rd party tools
find_package(Qt5 COMPONENTS Widgets Qml Quick REQUIRED)
# Directory with the source code
add_subdirectory(src)
包含在子目录中的CMakeLists.txt
include_directories(${Qt5Widgets_INCLUDE_DIRS} ${QtQml_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS} ${QtQml_DEFINITIONS} ${${Qt5Quick_DEFINITIONS}})
qt5_add_resources(QT_RESOURCES qml.qrc)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(PROJECT "virtualkeyboard-cmake-56202469")
project(${PROJECT})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -fstrict-aliasing -pedantic-errors -pedantic -Wno-deprecated-declarations -Wno-unused-variable")
if(NOT DEFINED HEADERS)
file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
endif()
if(NOT DEFINED SOURCES)
file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
endif()
source_group("Header Files" FILES ${HEADERS})
source_group("Source Files" FILES ${SOURCES})
add_executable(${PROJECT} ${HEADERS} ${SOURCES} ${QT_RESOURCES})
target_link_libraries(${PROJECT}
Qt5::Widgets
Qt5::Qml
Qt5::Quick
)
qml.qrc
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>
main.cpp
#include <QQuickView>
#include <QGuiApplication>
#include <QQmlEngine>
int main(int argc, char** argv)
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QGuiApplication app(argc, argv);
QQuickView view(QString("qrc:/main.qml"));
if (view.status() == QQuickView::Error)
return -1;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.show();
return app.exec();
}
main.qml
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.VirtualKeyboard 2.1
Rectangle {
width: 1280
height: 720
color: "#F6F6F6"
Flickable {
id: flickable
anchors.fill: parent
contentWidth: content.width
contentHeight: content.height
interactive: contentHeight > height
flickableDirection: Flickable.VerticalFlick
property real scrollMarginVertical: 20
MouseArea {
id: content
width: flickable.width
height: textEditors.height + 24
onClicked: focus = true
Column {
id: textEditors
spacing: 15
x: 12
y: 12
width: parent.width - 26
Label {
color: "#565758"
text: "Tap fields to enter text"
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: 22
}
TextField {
width: parent.width
placeholderText: "One line field"
onAccepted: passwordField.focus = true
}
TextField {
id: passwordField
width: parent.width
echoMode: TextInput.Password
placeholderText: "Password field"
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhPreferLowercase | Qt.ImhSensitiveData | Qt.ImhNoPredictiveText
onAccepted: upperCaseField.focus = true
}
}
}
}
}
答案 1 :(得分:0)
Qt的虚拟键盘只是find_package
可以加载的另一个模块。 cmake文件的最小示例是:
cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)
PROJECT("MyKeyboard")
set(CMAKE_PREFIX_PATH $ENV{QTDIR})
find_package(Qt5 COMPONENTS Widgets VirtualKeyboard REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
add_executable("MyKeyboard"
main.cpp
)
target_link_libraries("MyKeyboard" Qt5::Widgets Qt5::VirtualKeyboard)