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. No signal is emitted in testing for signals and slots
QtWS25 Last Chance

No signal is emitted in testing for signals and slots

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 776 Views
  • 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 Offline
    S Offline
    shravan_121
    wrote on last edited by
    #1

    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.

    BondrusiekB 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      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
      4
      • S Offline
        S Offline
        shravan_121
        wrote on last edited by shravan_121
        #3

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

        J.HilkJ VRoninV 2 Replies Last reply
        0
        • S shravan_121

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

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @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


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

          1 Reply Last reply
          1
          • S Offline
            S Offline
            shravan_121
            wrote on last edited by
            #5

            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
            0
            • S shravan_121

              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.

              BondrusiekB Offline
              BondrusiekB Offline
              Bondrusiek
              wrote on last edited by
              #6

              @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
              4
              • S Offline
                S Offline
                shravan_121
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • S shravan_121

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

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  @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
                  2
                  • VRoninV VRonin

                    @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

                    S Offline
                    S Offline
                    shravan_121
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      shravan_121
                      wrote on last edited by
                      #10
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        shravan_121
                        wrote on last edited by
                        #11

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

                        1 Reply Last reply
                        0
                        • VRoninV Offline
                          VRoninV Offline
                          VRonin
                          wrote on last edited by
                          #12

                          @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
                          4

                          • Login

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