3

My implementation of QTabWidget is not detecting its tabCloseRequested() and currentChanged() signals.

TileSheetManager::TileSheetManager(QWidget *parent)
: QTabWidget(parent)
{
    int w = WIDTH;
    int h = HEIGHT;

    this->setMinimumSize(w, h);
    this->setMaximumSize(w, h);

    setTabsClosable(true);
    setTabShape(QTabWidget::Rounded);

    connect(this, SIGNAL(tabCloseRequested(int index)), this, SLOT(closeTileWidget(int index)));
    connect(this, SIGNAL(currentChanged(int index)), this, SLOT(tabChanged(int index)));
}

qDebug() was not working for me, so I'm using a QMessageBox for this.

void TileSheetManager::closeTileWidget(int index)
{
   QMessageBox msgBox;
   msgBox.setText("Tab " + QString::number(index) + " removed!");
   msgBox.exec();

   TileWidget *t = (TileWidget *) widget(index) ;
   t->deleteLater();
   removeTab(index);
}

void TileSheetManager::tabChanged(int index)
{   
    QMessageBox msgBox;
    msgBox.setText("Tab was Changed!");
    msgBox.exec();

    TileWidget *t;

    for(int i = 0; i < count(); i++)
    {
        t = (TileWidget *) widget(i) ;
        t->resetSetBrush();
    }
} 

Tabs aren't getting closed, selected brushes are not being reset, and I get no messages, so I'm concluding the signals aren't being picked up. Which is weird, because I have used similar code for a previous project, in which case it worked.

Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
Rikonator
  • 1,830
  • 16
  • 27

1 Answers1

7

Don't use variable names in the connect function :

Note that the signal and slots parameters must not contain any variable names, only the type.

The connection should be

connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTileWidget(int)));
connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
pnezis
  • 12,023
  • 2
  • 38
  • 38
  • Thank you! It worked. My other signal-slot connection, with the variable name in the slot parameter, is working, though. Do you have any idea why? Thanks, again. – Rikonator Apr 02 '12 at 14:18
  • 2
    I have the same problem, and I don't have variable names in the connect, and still the signals are not picked up... any ideas? – Gal Goldman Aug 14 '12 at 11:57