未检测到QTabWidget的信号

时间:2012-04-02 13:38:01

标签: c++ qt qtabwidget

我的QTabWidget实现没有检测到它的tabCloseRequested()currentChanged()信号。

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()对我不起作用,所以我正在使用QMessageBox

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();
    }
} 

标签没有关闭,选定的画笔没有被重置,我没有收到任何消息,所以我得出的结论是没有拾取信号。这很奇怪,因为我在以前的项目中使用了类似的代码,在这种情况下它起作用了。

1 个答案:

答案 0 :(得分:7)

不要connect函数中使用变量名称:

  

请注意,信号和插槽参数不得包含   任何变量名称,只有类型。

连接应该是

connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTileWidget(int)));
connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
相关问题