3

私の 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()はうまくいかなかったので、これに a を使用して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();
    }
} 

タブが閉じられず、選択したブラシがリセットされず、メッセージも表示されないため、信号が検出されていないと結論付けています. 以前のプロジェクトで同様のコードを使用したことがあるため、これは奇妙です。

4

1 に答える 1

7

関数内で変数名を使用しないでくださいconnect:

シグナルとスロットのパラメーターには変数名を含めてはならず、型のみを含める必要があることに注意してください。

接続は

connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTileWidget(int)));
connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
于 2012-04-02T13:41:30.053 に答える