QML与CPP的交互:属性双元导致NaN
QML interaction with CPP : property double results in NaN
这是我的QML文件,它是一个简单的矩形,我想在其中显示从我的cpp代码(偏转,滚动和俯仰)中摘录的双值。
倾斜。QML:
import QtQuick 2.5
Rectangle {
id: myTilt
width: 100
height: 80
color: "grey"
border.color: "black"
anchors.margins: 15
property double yaw: 1.0 ;
property double roll: 0 ;
property double pitch: 0;
MouseArea {
anchors.fill: parent
onClicked: {
parent.color = Qt.rgba(Math.random(),Math.random(),Math.random(),1);
}
}
Text {
id: tilt
text: qsTr("Tilt :")
anchors.margins: 3
anchors.top: page.top
anchors.left: page.left
}
Text {
id: yaw
text: qsTr("Yaw : ") + Math.abs(yaw)
anchors.margins: 5
anchors.top: tilt.bottom
anchors.left: tilt.left
}
Text {
id: roll
text: qsTr("Roll : ") + roll
anchors.margins: 0
anchors.top: yaw.bottom
anchors.left: yaw.left
}
Text {
id: pitch
text: qsTr("Pitch : ") + pitch
anchors.margins: 0
anchors.top: roll.bottom
anchors.left: roll.left
}
}
这是我为了将我的cpp值链接到qml代码所尝试的。myTilt是一个QQuickItem。
void OpenGLManager::build_qml(QQuickWidget *tilt_qml) {
myTilt = tilt_qml->rootObject();
myTilt->setProperty("yaw", tilt[0]);
myTilt->setProperty("pitch", tilt[1]);
myTilt->setProperty("roll", tilt[2]);
}
void OpenGLManager::setDroneTilt(QList<double> yaw, QList<double> pitch, QList<double> roll)
{
tilt = QVector3D(10, 20, 30) ;
myTilt->setProperty("yaw", tilt[0]);
myTilt->setProperty("pitch", tilt[1]);
myTilt->setProperty("roll", tilt[2]);
}
我正在加载这个qml文件作为QtDesigner中设计的QQuickWidget的源。矩形显示良好,但不是我想要的值,我得到NaN Math.abs(偏角)和QQuickText(0x2a29100)的滚动和俯仰。
我使用Qt5.6
文本{id: 偏航text: qsTr("Yaw: ") + Math.abs( Yaw )锚。利润:5锚。上图:tilt.bottom锚。左:tilt.left}之前我想知道会出什么问题…
text元素的ID。
还有一个通用的做法:永远不要在c++代码中使用QML对象。所以,不要做
myTilt = tilt_qml->rootObject();
和myTilt->setProperty(...);
。创建一个c++类,让它可以从QML中使用。
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- C++概念:如何使用'concept'检查模板化结构的属性?
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 通过指向指针数组的指针访问子类的属性
- MSVC是否支持C++11样式的属性而不是__declspec
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 类的C++属性似乎已重新初始化
- Qt Quick-如何仅从c++代码与qml属性交互
- g++的分段错误(在NaN上使用to_string两次时)
- 输出是NaN,如何
- 用概念检查属性的类型
- C++如何将同一类的实例作为属性
- 为什么我在输出端得到 nan?
- 提升反序列化对象具有 nan 或 -nan 值
- 按多个属性排序
- 主函数参数的属性
- "perf_event_attr"结构的"read_format"属性的选项到底是什么?
- C++删除未使用的类属性会导致 std::logic_error
- Nan::ObjectWrap to Napi::Object Wrap 无法访问 JavaScript 中的属性
- QML与CPP的交互:属性双元导致NaN