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. how to switch over to page of staked widget by clicking the combobox text
Forum Updated to NodeBB v4.3 + New Features

how to switch over to page of staked widget by clicking the combobox text

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 4 Posters 380 Views
  • 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.
  • sankarapandiyanS Offline
    sankarapandiyanS Offline
    sankarapandiyan
    wrote on last edited by
    #1

    I Tried With push button , Its works Good

    void MainWindow::pushbutton1 clicked()
    {
        ui->stackedWidget->setCurrentIndex(1);
    
    }
    
    void MainWindow::pushbutton2clicked()
    {
        ui->stackedWidget->setCurrentIndex(2);
    
    }
    

    But ,in combo box i dont know how to set the text and get over to page of stack widget

    i have tried some thing like this but its not works , Getting Error

    void MainWindow::on_comboBox_currentIndexChanged(const QString line1  &arg1)
    {
        ui->stackedWidget->setCurrentIndex(1);
    
    }
    void MainWindow::on_comboBox_currentIndexChanged(const QString line2  &arg1)
    {
        ui->stackedWidget->setCurrentIndex(2);
    
    }
    void MainWindow::on_comboBox_currentIndexChanged(const QString line 3  &arg1)
    {
        ui->stackedWidget->setCurrentIndex(3);
    
    }
    
    

    Thanks in advance

    JonBJ 1 Reply Last reply
    0
    • J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #3

      @sankarapandiyan
      I think, you're working with the assumption, that the argument name has any meaning at all, which it doesn't!

      Take a look at the docu:
      https://doc.qt.io/qt-5/qcombobox.html#currentIndexChanged

      QComboBox has a currentIndexChanged signal, that has 2 overloads, one as string, one as int

      use the int one and do not rely on the connect by name feature, that's bad practice

      void MainWindow::pageSelectionChanged(int index)
      {
            ui->stackedWidget->setCurrentIndex(index);
      }
      
      .....
      connect(ui->comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::pageSelectionChanged);
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      3
      • sankarapandiyanS sankarapandiyan

        I Tried With push button , Its works Good

        void MainWindow::pushbutton1 clicked()
        {
            ui->stackedWidget->setCurrentIndex(1);
        
        }
        
        void MainWindow::pushbutton2clicked()
        {
            ui->stackedWidget->setCurrentIndex(2);
        
        }
        

        But ,in combo box i dont know how to set the text and get over to page of stack widget

        i have tried some thing like this but its not works , Getting Error

        void MainWindow::on_comboBox_currentIndexChanged(const QString line1  &arg1)
        {
            ui->stackedWidget->setCurrentIndex(1);
        
        }
        void MainWindow::on_comboBox_currentIndexChanged(const QString line2  &arg1)
        {
            ui->stackedWidget->setCurrentIndex(2);
        
        }
        void MainWindow::on_comboBox_currentIndexChanged(const QString line 3  &arg1)
        {
            ui->stackedWidget->setCurrentIndex(3);
        
        }
        
        

        Thanks in advance

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @sankarapandiyan
        You are showing 3 identical functions named on_comboBox_currentIndexChanged with the same argument numbers & types. That won't compile. The example you say "works" won't compile either, so it can't work. It helps if you only paste working code.

        Correct the code for push button you show so that it actually compiles and works. Then apply exactly the same principle for naming the 3 on_comboBox_currentIndexChanged methods.

        1 Reply Last reply
        2
        • J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #3

          @sankarapandiyan
          I think, you're working with the assumption, that the argument name has any meaning at all, which it doesn't!

          Take a look at the docu:
          https://doc.qt.io/qt-5/qcombobox.html#currentIndexChanged

          QComboBox has a currentIndexChanged signal, that has 2 overloads, one as string, one as int

          use the int one and do not rely on the connect by name feature, that's bad practice

          void MainWindow::pageSelectionChanged(int index)
          {
                ui->stackedWidget->setCurrentIndex(index);
          }
          
          .....
          connect(ui->comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::pageSelectionChanged);
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          3
          • A Offline
            A Offline
            alaaa
            Banned
            wrote on last edited by
            #4
            This post is deleted!
            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