views:

47

answers:

1

We're stumped as to why gcc complains about this line in our app:

doubleFrom->setValidator(new QDoubleValidator(doubleFrom));

with these complaints:

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*)

(I've chopped out long-winded paths to files, line numbers.)

Yes, setValidator wants to be fed a const QValidator*, and that's what we're doing in that one line of source. Why does gcc want to see a ')' prematurely, and think we're feeding setValidator an int*?

Of course, "this compiled fine yesterday, and we haven't changed anything. Really!"

+5  A: 

This is really basic and obvious, I know, but did you #include <QDoubleValidator>?
"Expected type-specifier before <identifier that should name a type>" almost always means that the type definition isn't visible.

Zack
That was it! Odd, how either it compiled without that before, or that line vanished without any record of that change in our svn repo. I had even tried svn revert with no luck.
DarenW
It may have compiled because another header included it and you included that header
David
@David: Just what I was about to say.
Zack
@David - yeah, that's our hunch, with some unknown number of nested #includes, but we're not going to spend time verifying it. This is a very large software system full of code surprises.
DarenW
So, is there an "oh, duh" badge for asking questions with obvious answerss?
DarenW
It's only obvious if you've seen that error message enough times to know what it really means. A lot of GCC's error messages assume you know the C++ grammar the way a compiler author knows it :-(
Zack