Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] emit signal problem error: passing 'const ' as 'this' argument of '' discards qualifiers
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 9.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ras123
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ras123
        wrote on last edited by
        #3

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

        it works OK

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved