PDA

View Full Version : 'fileMenu' was not declared in the scope



lapdx
27th November 2012, 14:56
#include "mainwindow.h"
#include "ui_mainwindow.h"

QAction *newAct;


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

newAct = new QAction(tr("&New"), this);
newAct->setShortcut(tr("Ctrl+N"));
newAct->setStatusTip(tr("Create a new file"));
connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));


fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(newAct);
}

MainWindow::~MainWindow()
{
delete ui;
}
Give me a error: 'fileMenu' was not declared in the scope. What is type of "filemenu"?

wysota
27th November 2012, 14:58
Yeah... and? Where did you declare fileMenu?

lapdx
27th November 2012, 15:11
filemenu declare after

QAction *newAct;
and we can show this code
QAction *newAct;
QMenu *fileMenu;; THANK U FOR THE HELP)

amleto
28th November 2012, 01:37
filemenu declare after
and we can show this code
THANK U FOR THE HELP)

Then please show the complete header code. Do not re-write it yourself - copy and paste (read my sig).

you declare QAction *newAct; in mainwindow.cpp - in global scope!


#include "mainwindow.h"
#include "ui_mainwindow.h"

QAction *newAct; // What is this for??? you say fileMenu is declared after this...


please use CODE tags for code, not quotes!!

Gokulnathvc
4th December 2012, 11:59
Atleast declare it now. or just include the header file here.
QMenu *fileMenu;; What is this then? Why are you using two semi colons here?

ChrisW67
6th December 2012, 22:16
fileMenu and newAct should be member variables of the MainWindow class or local variables in the constructor depending on the desired scope. They should not be declared as global variables as they are now.