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. Signal not connecting to Slot
Qt 6.11 is out! See what's new in the release blog

Signal not connecting to Slot

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.6k Views 2 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.
  • O Offline
    O Offline
    ofmrew
    wrote on last edited by
    #1

    The following code does not connect the signal to the slot:

    mycanvas.h

    signals:
    void updateTheMatrixTable();

    mainwindow.h

    public slots:
    void updateMatrixTable();

    mycanvas.cpp

    void MyCanvas::paintEvent(QPaintEvent *event)
    {
    QPainter p(this);
    . . . .
    emit updateTheMatrixTable();
    }

    mainwindow.cpp

    MainWindow::~MainWindow()
    {
    delete ui;
    //connect(ui->canvas, &MyCanvas::updateTheMatrixTable, this, &MainWindow::updateMatrixTable);
    connect(ui->canvas, SIGNAL (updateTheMatrixTable()),
    this, SLOT (updateMatrixTable()));
    }
    void MainWindow::updateMatrixTable()
    {
    qDebug() << "In MainWindow Slot";
    ui->tableWidget->setItem(1, 1, new QTableWidgetItem(QString::number(t.m11())));
    QTableWidgetItem *newItem12 = new QTableWidgetItem(QString::number(t.m12()));
    . . . .
    }

    As you can see I apears very simple, normally the signal and slot mechanism works with not problem, but in this case there is nothing to go on. Any suggestions?

    mrjjM 1 Reply Last reply
    0
    • O ofmrew

      The following code does not connect the signal to the slot:

      mycanvas.h

      signals:
      void updateTheMatrixTable();

      mainwindow.h

      public slots:
      void updateMatrixTable();

      mycanvas.cpp

      void MyCanvas::paintEvent(QPaintEvent *event)
      {
      QPainter p(this);
      . . . .
      emit updateTheMatrixTable();
      }

      mainwindow.cpp

      MainWindow::~MainWindow()
      {
      delete ui;
      //connect(ui->canvas, &MyCanvas::updateTheMatrixTable, this, &MainWindow::updateMatrixTable);
      connect(ui->canvas, SIGNAL (updateTheMatrixTable()),
      this, SLOT (updateMatrixTable()));
      }
      void MainWindow::updateMatrixTable()
      {
      qDebug() << "In MainWindow Slot";
      ui->tableWidget->setItem(1, 1, new QTableWidgetItem(QString::number(t.m11())));
      QTableWidgetItem *newItem12 = new QTableWidgetItem(QString::number(t.m12()));
      . . . .
      }

      As you can see I apears very simple, normally the signal and slot mechanism works with not problem, but in this case there is nothing to go on. Any suggestions?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @ofmrew
      Hi
      from quick glance it looks ok

      Please check what connect returns. ( just to be sure it says TRUE)

      Also , you seem to have the connect in the DESTRUCTOR ?

      That is very odd as that will first be called when main window is closed..
      Normally it would be in the constructor. After the call to setupUI(xx)

      1 Reply Last reply
      1
      • O Offline
        O Offline
        ofmrew
        wrote on last edited by
        #3

        You are correct, it is in the destructor, no wonder it would not work. The old eyes are really letting me down. Thanks so much, I feel like a real fool for not seeing that, it is so obvious now that you pointed it out. I should note that the reason I posted the question about getting the ui pointer was because this did not work.

        I moved the code in the DESTRUCTOR to the CONSTRUCTOR and it worked like it should.

        Thanks again.

        PS the spell checker used in the forum does not recognize destuctor, it should be updated for C++ terms.

        mrjjM 1 Reply Last reply
        1
        • O ofmrew

          You are correct, it is in the destructor, no wonder it would not work. The old eyes are really letting me down. Thanks so much, I feel like a real fool for not seeing that, it is so obvious now that you pointed it out. I should note that the reason I posted the question about getting the ui pointer was because this did not work.

          I moved the code in the DESTRUCTOR to the CONSTRUCTOR and it worked like it should.

          Thanks again.

          PS the spell checker used in the forum does not recognize destuctor, it should be updated for C++ terms.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ofmrew
          Np
          Yep, big surprise ;)
          Luckily it was easy to spot. ( mostly for a person that did not write the code)

          "destuctor" should be destructor, i think ?

          .

          1 Reply Last reply
          1
          • O Offline
            O Offline
            ofmrew
            wrote on last edited by
            #5

            It is destructor and it shows as a misspelled word--I am dyslexic and depend on spellcheckers.

            For my 50+ years of programming, it has always easier for someone else to see simple errors, and it will always be true.

            Thanks again.

            mrjjM 1 Reply Last reply
            0
            • O ofmrew

              It is destructor and it shows as a misspelled word--I am dyslexic and depend on spellcheckers.

              For my 50+ years of programming, it has always easier for someone else to see simple errors, and it will always be true.

              Thanks again.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @ofmrew
              Hmm i can't see it. i have installed another in chrome so i guess it wont show me what u see.

              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