PDA

View Full Version : GUI compile problem



waynew
17th October 2009, 01:20
I should be able to see why this is happening, but then again, I'm a newbie.

Compiler says 'actionQuit' was not declared in this scope.
Here is part of the mainwindow.cpp:



#include <QtGui>
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
setupActions();
mStatLabel = new QLabel;
statusBar()->addPermanentWidget(mStatLabel);
connect(textEdit, SIGNAL(textChanged()), this, SLOT(updateStats()));
updateStats();
}

void MainWindow::setupActions()
{
connect(actionQuit, SIGNAL(triggered(bool)),
qApp, SLOT(quit()));


I have checked to be sure the menu item is indeed actionQuit.
So what am I missing?

RSX
17th October 2009, 01:27
If you are using designer then actionQuit you call through ui.


connect(ui->actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));

waynew
17th October 2009, 02:00
Thanks RSX, that did it.

Just trying to get used to things in Qt.

wysota
17th October 2009, 10:12
Just trying to get used to things in Qt.

Your problem had nothing to do with Qt, it was strictly C++ related.

squidge
17th October 2009, 16:12
Indeed, if you want to refer to actionQuit as exactly that instead of ui->actionQuit, then you need to use multiple inheritance. An example is here (http://doc.trolltech.com/4.3/designer-using-a-component.html).

Lawand
20th October 2009, 19:41
If you are using designer then actionQuit you call through ui.


connect(ui->actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));

shoudn't it be ui.actionQuit ?

john_god
20th October 2009, 19:49
It's

ui.actionQuit
if ui was declared on the stack, and it's

ui->actionQuit
if ui was declare in heap, like a pointer

Lawand
20th October 2009, 19:54
Yes, but since it is auto-generated by Qt's UIC, then it must always be on the stack, right?

wysota
20th October 2009, 20:01
No, why...?

john_god
20th October 2009, 20:06
I just check in one project, it's in the heap


private:
Ui::area_dlg *m_ui;

Lawand
20th October 2009, 20:22
I see now, at first I thought that UIC always generates ui as an object rather than a pointer, but then I realized that it's the IDE that generated this, not UIC.

Sorry if I wasted your time :)

wysota
20th October 2009, 23:06
UIC generates classes, not objects.