令人困惑的gcc抱怨Qt4 setValidator的使用

Dar*_*enW 1 c++ gcc compiler-errors qt4

我们很困惑为什么gcc在我们的应用程序中抱怨这一行:

doubleFrom->setValidator(new QDoubleValidator(doubleFrom));
Run Code Online (Sandbox Code Playgroud)

抱怨这些:

error: expected type-specifier before 'QDoubleValidator'
error: expected `)' before 'QDoubleValidator'
error: no matching function for call to 'QLineEdit::setValidator(int*)'
candidates are: void QLineEdit::setValidator(const QValidator*)
Run Code Online (Sandbox Code Playgroud)

(我已经删除了文件,行号的冗长路径.)

是的,setValidator希望得到一个const QValidator*,这就是我们在这一行源代码中所做的事情.为什么gcc想要过早地看到')',并认为我们正在为setValidator提供一个int*?

当然,"昨天编好了,我们没有改变任何东西.真的!"

zwo*_*wol 5

这是非常基本和明显的,我知道,但是你#include <QDoubleValidator>呢?
"在应该命名类型的标识符之前的预期类型说明符>"几乎总是意味着类型定义不可见.