PDA

View Full Version : Can't compile custom QValidator



vieraci
22nd August 2009, 14:29
Can anyone see why this doesn't compile ?

header file:

#include <QValidator>
class QvDateValidator : public QValidator
{
public:
QvDateValidator(QObject * parent);
protected:
void fixup ( QString & input ) const;
QValidator::State validate ( QString & input, int & pos ) const;
};

source file:

#include "qvdatevalidator.h"

QvDateValidator::QvDateValidator(QObject * parent)
{
}

qvdatevalidator.cpp: In constructor ‘QvDateValidator::QvDateValidator(QObject*)à ¢â‚¬â„¢:
qvdatevalidator.cpp:4: error: no matching function for call to ‘QValidator::QValidator()’
/usr/include/qt4/QtGui/qvalidator.h:92: note: candidates are: QValidator::QValidator(const QValidator&)
/usr/include/qt4/QtGui/qvalidator.h:89: note: QValidator::QValidator(QValidatorPrivate&, QObject*)
/usr/include/qt4/QtGui/qvalidator.h:88: note: QValidator::QValidator(QObjectPrivate&, QObject*)
/usr/include/qt4/QtGui/qvalidator.h:64: note: QValidator::QValidator(QObject*)
qvdatevalidator.cpp: At global scope:

caduel
22nd August 2009, 15:12
because (as the compiler tried to tell you) QValidator does not have a default constructor (one without args). You need to pass parent to it:


QvDateValidator::QvDateValidator(QObject * parent)
: QValidator(parent)
{}