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. [Solved] Signals & slots, connect menu from QComboBox to slot
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 12.3k Views 1 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.
  • yczoY Offline
    yczoY Offline
    yczo
    wrote on last edited by yczo
    #1

    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(){
    
    }
    
    Joel BodenmannJ 1 Reply Last reply
    0
    • yczoY yczo

      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(){
      
      }
      
      Joel BodenmannJ Offline
      Joel BodenmannJ Offline
      Joel Bodenmann
      wrote on last edited by
      #2

      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.

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      1 Reply Last reply
      0
      • yczoY Offline
        yczoY Offline
        yczo
        wrote on last edited by
        #3

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

        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