QML对象在显示时不更新 我在C++中创建了一个QML对象。在main方法中,我可以设置在自定义QML对象中定义的各种属性。当从main方法设置时,各种属性将按预期显示。当我在更新方法中设置属性时,显示永远不会更新。我已经验证了自定义QML对象中的关联方法正在接收我传递给它的值。为什么我的显示器不能更新

QML对象在显示时不更新 我在C++中创建了一个QML对象。在main方法中,我可以设置在自定义QML对象中定义的各种属性。当从main方法设置时,各种属性将按预期显示。当我在更新方法中设置属性时,显示永远不会更新。我已经验证了自定义QML对象中的关联方法正在接收我传递给它的值。为什么我的显示器不能更新,c++,qt,qml,C++,Qt,Qml,main.cpp 必须使用该方法,以便重新绘制GUI,因此每次修改用于绘制的属性时都必须调用该方法。举例来说: void HorizontalBarGraph::setActualValue(qreal actualValue) { if(_actualValue == actualValue) return; _actualValue = actualValue; update(); emit

main.cpp

必须使用该方法,以便重新绘制GUI,因此每次修改用于绘制的属性时都必须调用该方法。举例来说:

void HorizontalBarGraph::setActualValue(qreal actualValue) {     
    if(_actualValue == actualValue)         
        return;      
    _actualValue = actualValue;     
    update();  
    emit actualValueChanged(); 
}
必须使用该方法,以便重新绘制GUI,因此每次修改用于绘制的属性时都必须调用该方法。举例来说:

void HorizontalBarGraph::setActualValue(qreal actualValue) {     
    if(_actualValue == actualValue)         
        return;      
    _actualValue = actualValue;     
    update();  
    emit actualValueChanged(); 
}

请提供一份报告。QGUI应用程序在哪里?@eyllanesc帖子已更新为包含所有代码。就是这样。。。我遵循的示例从未调用过update,我觉得这有点奇怪。但是我从来没有把二和二放在一起。你能给我一个答案吗?我会接受的。请提供一个答案。QGUI应用程序在哪里?@eyllanesc帖子已更新为包含所有代码。就是这样。。。我遵循的示例从未调用过update,我觉得这有点奇怪。但是我从来没有把二和二放在一起。你能发个帖子作为答复吗?我会接受的?
#ifndef HORIZONTALBARGRAPH_H
#define HORIZONTALBARGRAPH_H

#include <QObject>
#include <QQuickPaintedItem>

class HorizontalBarGraph : public QQuickPaintedItem
{
    Q_OBJECT

    Q_PROPERTY(qreal horizontalBarGraphWidth READ getHorizontalBarGraphWidth WRITE setHorizontalBarGraphWidth NOTIFY horizontalBarGraphWidthChanged)
    Q_PROPERTY(qreal horizontalBarGraphHeight READ getHorizontalBarGraphHeight WRITE setHorizontalBarGraphHeight NOTIFY horizontalBarGraphHeightChanged)
    Q_PROPERTY(qreal minValue READ getMinValue WRITE setMinValue NOTIFY minValueChanged)
    Q_PROPERTY(qreal maxValue READ getMaxValue WRITE setMaxValue NOTIFY maxValueChanged)
    Q_PROPERTY(qreal actualValue READ getActualValue WRITE setActualValue NOTIFY actualValueChanged)
    Q_PROPERTY(QString sensorName READ getSensorName WRITE setSensorName NOTIFY sensorNameChanged)
    Q_PROPERTY(QString units READ getUnits WRITE setUnits NOTIFY unitsChanged)


public:
    HorizontalBarGraph(QQuickItem *parent = 0);
    virtual void paint(QPainter *painter);

    qreal   getHorizontalBarGraphWidth();
    qreal   getHorizontalBarGraphHeight();
    qreal   getMinValue();
    qreal   getMaxValue();
    qreal   getActualValue();
    QString getSensorName();
    QString getUnits();

    void    setHorizontalBarGraphWidth(qreal width);
    void    setHorizontalBarGraphHeight(qreal height);
    void    setMinValue(qreal minValue);
    void    setMaxValue(qreal maxValue);
    void    setActualValue(qreal actualValue);
    void    setSensorName(QString sensorName);
    void    setUnits(QString units);

signals:
    void    horizontalBarGraphWidthChanged();
    void    horizontalBarGraphHeightChanged();
    void    minValueChanged();
    void    maxValueChanged();
    void    actualValueChanged();
    void    sensorNameChanged();
    void    unitsChanged();

private:
    qreal   _horizontalBarGraphWidth;
    qreal   _horizontalBarGraphHeight;
    qreal   _minValue;
    qreal   _maxValue;
    qreal   _actualValue;
    QString _sensorName;
    QString _units;
    qreal   scale(qreal input, qreal inputMin, qreal inputMax, qreal outputMin, qreal outputMax);

};

#endif // HORIZONTALBARGRAPH_H
import QtQuick 2.11
import QtQuick.Window 2.11
import com.kubie.horizontalBarGraph 1.0

Window {
    id: window
    visible: true
    width: 800
    height: 480
    title: qsTr("REDNEKSLDHLR")
    color: "black"

//    Rectangle
//    {
//        width: 260
//        height: 75
//        color: "#7a0505"
//        anchors.bottom: parent.bottom
//        anchors.bottomMargin: 0
//        anchors.left: parent.left
//        anchors.leftMargin: 0
//    }

    HorizontalBarGraph {
        objectName: "oilTemp"
        anchors.left: parent.left
        anchors.leftMargin: 0
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 0
        width: horizontalBarGraphWidth
        height: horizontalBarGraphHeight
    }

    HorizontalBarGraph {
        objectName: "oilPressure"
        anchors.left: parent.left
        anchors.leftMargin: 0
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 75
        width: horizontalBarGraphWidth
        height: horizontalBarGraphHeight
    }

    HorizontalBarGraph {
        objectName: "coolantTemp"
        anchors.right: parent.right
        anchors.rightMargin: 0
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 0
        width: horizontalBarGraphWidth
        height: horizontalBarGraphHeight
    }

    HorizontalBarGraph {
        objectName: "coolantPressure"
        anchors.right: parent.right
        anchors.rightMargin: 0
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 75
        width: horizontalBarGraphWidth
        height: horizontalBarGraphHeight
    }

    HorizontalBarGraph {
        objectName: "intakeAirTemp"
        anchors.left: parent.left
        anchors.leftMargin: parent.width / 2 - width / 2;
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 0
        width: horizontalBarGraphWidth
        height: horizontalBarGraphHeight
    }

        HorizontalBarGraph {
            objectName: "engineRPM"
            anchors.left: parent.left
            anchors.leftMargin: parent.width / 2 - width / 2;
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 75
            width: horizontalBarGraphWidth
            height: horizontalBarGraphHeight
    }


}
void HorizontalBarGraph::setActualValue(qreal actualValue) {     
    if(_actualValue == actualValue)         
        return;      
    _actualValue = actualValue;     
    update();  
    emit actualValueChanged(); 
}