1 of 2 EMIT functions does not work



  • In my Setup window I want to set the autoRepeatInterval of certain pushbuttons. There are 4 pushbuttons in my mainwindow and there are 4 pushbuttons in the keyboard window. And the ones of my keyboard window aren't getting new values.

    In Setup class I do:

    setup.h
    
    signals:
    void changeInterval(int value);
    void changeIntervalKeyboard(int value);
    
    setup.cpp
    
    void Setup::on_plus_clicked()
    {  
        emit changeIntervalKeyboard(++value);
        emit changeInterval(value);
        ui->intervalLabel->setText(QString::number(value));
    }
    
    void Setup::on_minus_clicked()
    {
        emit changeIntervalKeyboard(--value);
        emit changeInterval(value);
        ui->intervalLabel->setText(QString::number(value));
    }
    

    In mainwindow.cpp:

    connect(settings, &Setup::changeInterval, this, &MainWindow::changeInterval);
    
    void MainWindow::changeInterval(int value)
    {
       ui->DOWN->setAutoRepeatInterval(value);
       ui->UP->setAutoRepeatInterval(value);
       ui->LEFT->setAutoRepeatInterval(value);
       ui->RIGHT->setAutoRepeatInterval(value);
       qDebug() << "i'm @ Mainwindow";
    }
    

    In mainwindow.h

    void changeInterval(int value);
    

    in keyboard.cpp

    connect(settings, &Setup::changeIntervalKeyboard, this, &Keyboard::changeIntervalKeyboard);
    
    
    void Keyboard::changeIntervalKeyboard(int value)
    {
       ui->down->setAutoRepeatInterval(value); // button names are correct
       ui->up->setAutoRepeatInterval(value);
       ui->left->setAutoRepeatInterval(value);
       ui->right->setAutoRepeatInterval(value);
       qDebug() << "I'm @ keyboard";
    }
    

    and in keyboard.h

    void changeIntervalKeyboard(int value);
    

    Whatever I do or try, I am never seeing the debug text: "I'm @ keyboard"
    I tried in keyboard.cpp

    connect(settings, &Setup::changeInterval, this, &Keyboard::changeIntervalKeyboard);
    

    But no effect. I looked at it about ~20 times now but I cannot find any reason why "emit changeIntervalKeyboard(--value);" is not working and why the other one is working. As far as I can see I did the exact same thing for both of them, so now I need others to see... because right now I am not seeing anything anymore -_-*



  • @bask185 said in 1 of 2 EMIT functions does not work:

    In mainwindow.cpp:
    connect(settings,

    @bask185 said in 1 of 2 EMIT functions does not work:

    in keyboard.cpp
    connect(settings,

    are you sure these 2 settings pointers point to the same object?



  • I am not sure, now that you mention I don't think so. 'settings' is the Setup object which is constructed in the MainWindow.h file

    private:
    
    Setup *settings;
    

    I don't know how I can let the keyboard class point at the 'settings' object in the MainWindow.



  • @bask185 Where do you create Keyboard object?



  • @Eligijus said in 1 of 2 EMIT functions does not work:

    @bask185 Where do you create Keyboard object?

    Mainwindow



  • @bask185 Then just make a connection inside MainWindow like so:
    connect(settings, &Setup::changeIntervalKeyboard, !Keyboard object name!, &Keyboard::changeIntervalKeyboard);
    change !Keyboard object name! to your Keyboard object name.



  • @Eligijus A thnx dat solved the problem

    I'm @ keyboard
    i'm @ Mainwindow
    

    only had to move "void changeIntervalKeyboard(int Value);" from private to public slots.


Log in to reply