Nominate our 2022 Qt Champions!

connect button to stackWidget and radioButton to comboBox

  • I want to connect pushButton to stackWidget index I used

    connect(ui->user, SIGNAL(clicked(bool)), ui->stackedWidget,SLOT(setCurrentIndex(int)));

    It is not complete and it does not work

    And to connect radioButton to the comboBox (if radioButton was hit, comboBox would be enabled) I used


    It also not complete and it does not work
    How should I do this without defining any function?

  • Lifetime Qt Champion

    connect(ui->user, SIGNAL(clicked(bool)), ui->stackedWidget,SLOT(setCurrentIndex(int)));

    Can never work as clicked can maximum send a bool and
    setCurrentIndex expects and int that tells what index to go to.

    What do u try to make it do with one button ?

    for combobox
    should work.
    But not sure it works as you want as radio buttons normally comes in a group.
    If you just have 1 radiobutton, its not possible to unselect it again.

    If just to enable combo, then QCheckbox might be better.

  • I did this to change the page

    void Healthy::on_user_clicked()

    But I want to use a connection to do this
    comboBox is disabled for the first time


    I used QCheckBox, but when checking QCheckBox ,the comboBox is not enabled


    when I run the program I get this

    QObject::connect: Incompatible sender/receiver arguments
            QCheckBox::clicked() --> QComboBox::setEnabled(bool)

  • Lifetime Qt Champion

    But dont u need to slots like
    nextPage and prevPage ?
    to go back and forth. You can use lambdas for compact design.

    you forgot the parameter type
    also connects return true/false so u can spot when you have made error.

  • connect(ui->checkBox_co,SIGNAL(clicked(bool)),ui->comboBox_co,SLOT(setEnabled(bool)));

    And I use this for change page

    connect(ui->user, &QAbstractButton::clicked, [=](bool b){ui->stackedWidget->setCurrentIndex(5);});

    it work thanks to u

  • Lifetime Qt Champion

    Ok super.
    So you just need button to go exact page. and not navigate back and forth.

  • @mrjj said in connect button to stackWidget and radioButton to comboBox:

    So you just need button to go exact page. and not navigate back and forth.

    at this time ,yes

Log in to reply