[Solved] Signals & slots, connect menu from QComboBox to slot



  • Hello folks, I created a small menu with QComboBox to select, between 3 variables.

    My question is, How can make the connection between the menus and a respective slot? (i did try but I don't get)

    any help will wellcomed
    Thanks in advance.
    Greetings

    /#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QToolButton>
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        setFixedSize(1333,768);
    
    
            QComboBox *comboBox = new QComboBox(this);
            comboBox->addItem(tr("Automatic"));
            comboBox->addItem(tr("Manual"));
            comboBox->addItem(tr("Off"));
    
            QComboBox *iconComboBox = new QComboBox;
            iconComboBox->addItem(QIcon(":/icons/engranaje.png"), tr("Automatic"));
            iconComboBox->addItem(QIcon(":/icons/s_mano.png"), tr("Manual"));
            iconComboBox->addItem(QIcon(":/icons/s_off.png"), tr("Off"));
    
            connect(comboBox->tr(),SIGNAL(triggered()),this,SLOT(slotTest())); //<-- how can i make this?
    }
    //************************************************
    void MainWindow::slotTest(){
    
    }
    


  • The QComboBox provides signals such as currentIndexChanged() and currentTextChanged() that you can use for this purpose. The parameters passed are either the index of the element in the combobox or the item text.

    You would do something like:

    connect(comboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(comboboxItemChanged(QString)));
    

    I hope that helps.



  • Thank you very much,
    It has worked!!!!


Log in to reply
 

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