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. QTabWidget: tabCloseRequested(int) not emitted
Qt 6.11 is out! See what's new in the release blog

QTabWidget: tabCloseRequested(int) not emitted

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.5k 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    According to the documentation:

    This signal is emitted when the close button on a tab is clicked

    in my application (Qt 5.11.0) I placed a QTabWidget in my QMainWindow using the designer. Then I set the tabClosable property to true. In my code I created this slot:

    void MainWindow::on_tabView_tabCloseRequested(int index)
    {
        qDebug() << "close requested" << index;
    }
    

    tabView is the name of the QTabWidget. The tabs are added dynamically in this way:

    void MainWindow::createViewTabs(QStringList names)
    {
        foreach (QString name, names)
        {
            QWidget *widget = new QWidget(ui->tabView);
            widget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);        
            ui->tabView->addTab(widget, name);
        }
    }
    

    but when I click the close button the signal is not emitted - or at least the slot is not executed. I don't have any warning about wrong signal-slot connection.

    Do you see any evidence of errors here?

    jsulmJ 1 Reply Last reply
    0
    • M Mark81

      According to the documentation:

      This signal is emitted when the close button on a tab is clicked

      in my application (Qt 5.11.0) I placed a QTabWidget in my QMainWindow using the designer. Then I set the tabClosable property to true. In my code I created this slot:

      void MainWindow::on_tabView_tabCloseRequested(int index)
      {
          qDebug() << "close requested" << index;
      }
      

      tabView is the name of the QTabWidget. The tabs are added dynamically in this way:

      void MainWindow::createViewTabs(QStringList names)
      {
          foreach (QString name, names)
          {
              QWidget *widget = new QWidget(ui->tabView);
              widget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);        
              ui->tabView->addTab(widget, name);
          }
      }
      

      but when I click the close button the signal is not emitted - or at least the slot is not executed. I don't have any warning about wrong signal-slot connection.

      Do you see any evidence of errors here?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mark81 Did you try to connect the signal to your slot manually to see whether it makes a difference?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        @jsulm good catch. Using:

        connect(ui->tabView, &QTabWidget::tabCloseRequested, this, &MainWindow::tabView_tabCloseRequested);
        

        it works.
        But I dont't understand what's wrong. I created the implicit slot right-clicking on the QTabWidget in the designer and selecting "go to slot". As said, there were no warnings about any syntax error in the connection.

        jsulmJ 1 Reply Last reply
        0
        • M Mark81

          @jsulm good catch. Using:

          connect(ui->tabView, &QTabWidget::tabCloseRequested, this, &MainWindow::tabView_tabCloseRequested);
          

          it works.
          But I dont't understand what's wrong. I created the implicit slot right-clicking on the QTabWidget in the designer and selecting "go to slot". As said, there were no warnings about any syntax error in the connection.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mark81 said in QTabWidget: tabCloseRequested(int) not emitted:

          right-clicking on the QTabWidget in the designer and selecting "go to slot"

          I did the same and it works, but I did not add tabs manually.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          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