I'm currently writing a small utility and I've created custom inner-widgets for my main window that will throw their events / call backs back up to the top-level controller. Unfortunately the events do not seem to be working with the signals and slots mechanism.

I suspect I've made some obvious mistake, but having spent an entire day looking at this, I'm at a loss to find any answers. A snippet of code is below:

maintabs.h

Qt Code:
  1. #ifndef MAINTABS_H
  2. #define MAINTABS_H
  3.  
  4. #include "pagewidget.h"
  5.  
  6. #include "ui_maintabs.h"
  7.  
  8. class MainTabs : public QTabWidget
  9. {
  10. Q_OBJECT
  11.  
  12. public:
  13. MainTabs(QWidget *parent = 0);
  14. void addPage(PageWidget *page, const char *text);
  15.  
  16. public slots:
  17. void removePage(PageWidget *page);
  18.  
  19. private:
  20. Ui::MainTabs ui;
  21. };
  22.  
  23. #endif
To copy to clipboard, switch view to plain text mode 

maintabs.cpp

Qt Code:
  1. #include <QtGui>
  2.  
  3. #include "maintabs.h"
  4.  
  5. MainTabs::MainTabs(QWidget *parent)
  6. : QTabWidget(parent)
  7. {
  8. ui.setupUi(this);
  9. }
  10.  
  11. void MainTabs::addPage(PageWidget *page, const char *text)
  12. {
  13. connect(page, SIGNAL(pageClosed(PageWidget)), this, SLOT(removePage(PageWidget)));
  14. this->addTab(page, QString());
  15. this->setTabText(this->indexOf(page), QApplication::translate("MainWindow", text, 0, QApplication::UnicodeUTF8));
  16. }
  17.  
  18. void MainTabs::removePage(PageWidget *page)
  19. {
  20. this->removeTab(this->indexOf(page));
  21. }
To copy to clipboard, switch view to plain text mode 

pagewidget.h

Qt Code:
  1. #ifndef PAGEWIDGET_H
  2. #define PAGEWIDGET_H
  3.  
  4. #include "ui_pagewidget.h"
  5.  
  6. class PageWidget : public QWidget
  7. {
  8. Q_OBJECT
  9.  
  10. public:
  11. PageWidget();
  12. void setPage(QWidget* page);
  13.  
  14. public slots:
  15. void closeClicked();
  16.  
  17. signals:
  18. void pageClosed(PageWidget*);
  19.  
  20. private:
  21. Ui::PageWidget ui;
  22. };
  23.  
  24. #endif
To copy to clipboard, switch view to plain text mode 

pagewidget.cpp
Qt Code:
  1. #include <QtGui>
  2.  
  3. #include "pagewidget.h"
  4.  
  5. PageWidget::PageWidget()
  6. : QWidget()
  7. {
  8. ui.setupUi(this);
  9. }
  10.  
  11. void PageWidget::setPage(QWidget* page)
  12. {
  13. ui.verticalLayout->removeWidget(ui.mainWidget);
  14. ui.verticalLayout->removeWidget(ui.buttonBox);
  15. ui.verticalLayout->addWidget(page);
  16. ui.verticalLayout->addWidget(ui.buttonBox);
  17.  
  18. connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(closeClicked()));
  19. }
  20.  
  21. void PageWidget::closeClicked()
  22. {
  23. emit pageClosed(this);
  24. }
To copy to clipboard, switch view to plain text mode 

Now the PageWidget is a custom page object that all tab pages will inherit from. The MainTabs is my QTabWidget object. The idea is for each page to have a 'Close' button and when that is clicked an event is shot up to the main controller of the QMainWindow object. Unfortunately, although the PageWidget::closeClicked() method is invoked, the pageClosed(PageWidget*) method does not seem to be getting hit within the MainTabs class.

I hope I've provided enough information, and that someone is inclined to provide me with an answer. I'm assuming it's simply a lack of knowledge on my part of the SLOTS and SIGNALS mechanism within Qt.

And of course, any tips on how to improve my approach would be welcome.

Regards,

P.