gpt4 book ai didi

c++ - 从 C++ 获取 QML Editbox 的值

转载 作者:搜寻专家 更新时间:2023-10-31 00:14:34 26 4
gpt4 key购买 nike

我在 QML 中创建了一个带有一些文本框的 QtQuick 应用程序。我想在我的 C++ 代码中使用这些文本框的值。那么如何从 C++ 代码中获取这些值呢?

最佳答案

它可以是这样的:

QML 文件:

Item{
id: root

signal textChanged(string msg)

TextInput
{
id: inputText
anchors.horizontalCenter: root.horizontalCenter
anchors.verticalCenter: root.verticalCenter

text : ""
inputMethodHints: Qt.ImhNoPredictiveText
selectByMouse: true

onAccepted: {
inputText.focus = false;
Qt.inputMethod.hide();
root.textChanged(inputText.text);
}

}
}

ِ你可以将你的 qml 信号连接到 cpp 中的某个插槽,例如:

QObject::connect((QObject *)viewer.rootObject(), SIGNAL(textChanged(QString)), this, SLOT(someSlot(QString)));

关于c++ - 从 C++ 获取 QML Editbox 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22658561/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com