如何避免浮点值的 qWarning

How to avoid qWarning of float values

我有以下代码来设置变量:

void TypeLogVisualization::setGain(double gain)
{
qWarning("Floating point comparison needs context sanity check");
if (qFuzzyCompare(m_gain, gain) || gain < 1.0 || gain > 2.1)
    return;

m_gain = gain;
setPath();
emit gainChanged(m_gain);
}

可变增益在QML文件中设置,如下代码:

function gainMinus(){
    log.setGain(log.gain-=0.1)
}

function gainPlus(){
    log.setGain(log.gain+=0.1)
}

log 是包含 "setGain" 的类的对象,gain 是一个 QProperty。我真的很想知道如何避免该警告:浮点比较需要上下文完整性检查

正如大家所说,唯一的方法是删除这些行