Signal not connecting to Slot



  • 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?


  • Qt Champions 2016

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



  • 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.


  • Qt Champions 2016

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

    .



  • 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.


  • Qt Champions 2016

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


Log in to reply
 

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