[solved] emit signal problem error: passing 'const ' as 'this' argument of '' discards qualifiers



  • Hi,
    I tried to emit signal from a class, given below,
    @#include <QValidator>

    class BlankCheck : public QValidator
    {
    Q_OBJECT
    public:
    explicit BlankCheck(QObject *parent = 0);

    private:
    State validate(QString &input, int &pos) const;
    void fixup(QString &input) const;

    signals:
    void invalidEntry();
    };@

    @BlankCheck::BlankCheck(QObject *parent) :
    QValidator(parent)
    {
    }

    QValidator::State BlankCheck::validate(QString &input, int &pos) const
    {
    if(!input.isEmpty())
    return Acceptable;
    return Intermediate;
    }

    void BlankCheck::fixup(QString &input) const
    {
    QMessageBox msg;
    msg.setWindowTitle("Invalid Column");
    msg.setIcon(QMessageBox::Information);
    msg.setText("Colum should not be left blank");
    msg.exec();
    emit invalidEntry();
    return;
    }@

    And gets the following error,
    blankcheck.cpp:24: error: passing 'const BlankCheck' as 'this' argument of 'void BlankCheck::invalidEntry()' discards qualifiers

    How to solve the issue?
    Thanking You,
    Ras



  • Good question!
    "This discussion":http://lists.trolltech.com/qt-interest/2005-09/thread01411-0.html might be interesting for you on this. A good question is raised in it though. A const method should have no side effects. How are you going to guarantee that if you emit a signal and whoever is connected to that can do whatever they want?



  • I solved the problem by declaring
    @signals:
    void invalidEntry() const;@

    it works OK


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.