Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved No signal is emitted in testing for signals and slots

    General and Desktop
    4
    12
    281
    Loading More Posts
    • 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.
    • S
      shravan_121 last edited by

      test.cpp:
      QTest::keyClick(ccalculator->plusButton,Qt::Key_Plus);
      QSignalSpy spy(ccalculator,&Calculator::addbuttonClicked);
      QTest::keyClick(ccalculator->plusButton,Qt::Key_Plus);
      QCOMPARE(spy.count(),1);
      the result shows the actual value is 0 and expected value is 1.

      calculator.cpp:
      plusButton = createButton(tr("+"), SLOT(additiveOperatorClicked()this));
      connect(plusButton,SIGNAL(addbuttonClicked()),this,SLOT(additiveOperatorClicked()));
      additiveOperatorClicked()
      {
      //some codes
      emit addbuttonClicked(tr("+"));
      }
      can anyone help me to solve this problem.

      Bondrusiek 1 Reply Last reply Reply Quote 0
      • VRonin
        VRonin last edited by

        make sure all the connections were successful. My recommendation is to use Qt5 connection syntax but if you stick with Qt4 version then wrap the connect statement in a Q_ASSUME() (so it asserts if the connection fails)

        Q_ASSUME(connect(plusButton,SIGNAL(addbuttonClicked()),this,SLOT(additiveOperatorClicked())));

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply Reply Quote 4
        • S
          shravan_121 last edited by shravan_121

          It shows me error ::Qobject::connect:no such signal Button::additivieoperatorClickedsignal()

          J.Hilk VRonin 2 Replies Last reply Reply Quote 0
          • J.Hilk
            J.Hilk Moderators @shravan_121 last edited by

            @shravan_121
            pls post your whole connect statement

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

            Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply Reply Quote 1
            • S
              shravan_121 last edited by

              calculator.h:
              class Calculator : public QWidget
              {
              Q_OBJECT

              public:
              Button *plusButton;
              Button *minusButton;
              Button *timesButton;
              Button *divisionButton;
              Calculator(QWidget *parent = 0);
              public slots:
              void digitClicked();
              void additiveOperatorClicked();
              void multiplicativeOperatorClicked();
              signals:
              void addbuttonClicked(const QString &data);
              void multiplybuttonClicked(const QString &data);
              void digitclickedsignal(const QString &data);

              calculator.cpp:
              Calculator::Calculator(QWidget *parent)
              : QWidget(parent)
              {
              plusButton = createButton(tr("+"), SLOT(additiveOperatorClicked()this));

              connect(plusButton,SIGNAL(addbuttonClicked()),this,SLOT(additiveOperatorClicked()));

              void Calculator::additiveOperatorClicked()
              {
              Button *clickedButton = qobject_cast<Button *>(sender());
              QString clickedOperator = clickedButton->text();
              double operand = display->text().toDouble();
              if (!pendingMultiplicativeOperator.isEmpty()) {
              //! [12] //! [13]
              if (!calculate(operand, pendingMultiplicativeOperator)) {
              abortOperation();
              return;
              }
              display->setText(QString::number(factorSoFar));
              operand = factorSoFar;
              factorSoFar = 0.0;
              pendingMultiplicativeOperator.clear();

              }
              
              if (!pendingAdditiveOperator.isEmpty()) {
                  if (!calculate(operand, pendingAdditiveOperator)) {
                      abortOperation();
                      return;
                  }
                  display->setText(QString::number(sumSoFar));
              } else {
                  sumSoFar = operand;
              }
              pendingAdditiveOperator = clickedOperator;
              waitingForOperand = true;
              
               emit addbuttonClicked(tr("+"));
              
              1 Reply Last reply Reply Quote 0
              • Bondrusiek
                Bondrusiek @shravan_121 last edited by

                @shravan_121 On first view you have bad syntax. Look on signal emit addbuttonClicked(tr("+")); which has one argument QString. In connect function you use signal without argument ```
                connect(plusButton,SIGNAL(addbuttonClicked()),this,SLOT(additiveOperatorClicked()));.
                Try to replace signal on
                void addbuttonClicked()
                or change function slot with one argument ie

                void additiveOperatorClicked(QString)

                and use this in connect

                connect(plusButton,SIGNAL(addbuttonClicked(QString)),this,SLOT(additiveOperatorClicked(QString)));

                1 Reply Last reply Reply Quote 4
                • S
                  shravan_121 last edited by

                  But after that i am getting same error: no such signal additiveoperatorclicked(QString)
                  no such slot addbuttonclicked(QString)

                  1 Reply Last reply Reply Quote 0
                  • VRonin
                    VRonin @shravan_121 last edited by

                    @shravan_121 said in No signal is emitted in testing for signals and slots:

                    no such signal Button::additivieoperatorClicked

                    And this is the problem additivieoperatorClicked is a signal of Calculator not of Button. You are trying to connect with a receiver being a pointer to Button

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    S 1 Reply Last reply Reply Quote 2
                    • S
                      shravan_121 @VRonin last edited by

                      @VRonin I dont know the actual solution can you please suggest a possible solution for the error.

                      1 Reply Last reply Reply Quote 0
                      • S
                        shravan_121 last edited by

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • S
                          shravan_121 last edited by

                          I don't know the actual solution can you please suggest a possible solution for the error.

                          1 Reply Last reply Reply Quote 0
                          • VRonin
                            VRonin last edited by

                            @shravan_121 said in No signal is emitted in testing for signals and slots:

                            connect(plusButton,SIGNAL(addbuttonClicked()),

                            The problem is here. addbuttonClicked is a signal of Calculator but plusButton is of type Button.
                            So either the sender (the first argument) or the signal (the second) must be changed to make sense

                            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                            ~Napoleon Bonaparte

                            On a crusade to banish setIndexWidget() from the holy land of Qt

                            1 Reply Last reply Reply Quote 4
                            • First post
                              Last post