[Qt-interest] Single inheritance approach: problem connecting

John McClurkin jwm at nei.nih.gov
Fri Nov 6 13:47:19 CET 2009


Rui Maciel wrote:
> I've created a basic main window UI through Qt Designer, which has a QAction entry named actionNew located in 
> the main window's file->new menu entry and I've followed the single inheritance approach suggested in the 
> documentation. The child class's constructor is as follows:
> 
> <code>
> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
> {
>         ui.setupUi(this);
> 
>         commandLineDockWidget = new CommandLineDockWidget(this);
>         this->addDockWidget(static_cast<Qt::DockWidgetArea>(8), commandLineDockWidget);
> 
>         // connect signals and slots
>         connect(ui.actionNew, Q_SIGNAL(triggered()), this, Q_SLOT(newProject()));
> }
> </code>
> 
> When I build the project, the compiler throws the following error:
> 
> <error>
> MainWindow.c++: In constructor ‘MainWindow::MainWindow(QWidget*)’:
> MainWindow.c++:13: error: ‘triggered’ was not declared in this scope
> make: *** [MainWindow.o] Error 1
> </error>
> 
> 
> The signal triggered() should be already declared, as it's a member/signal of QAction. So, why is this not 
> working?
> 
> 
> Thanks in advance,
> Rui Maciel
Using the single inheritance approach, the QAction object is a member of 
the ui class, not your MainWindow class. Personally, I prefer the double 
inheritance approach. This eliminates the need for the all the ui. and 
ui-> in the class.



More information about the Qt-interest-old mailing list