Results 1 to 6 of 6

Thread: 'fileMenu' was not declared in the scope

  1. #1
    Join Date
    Nov 2012
    Posts
    16
    Qt products
    Qt4

    Default 'fileMenu' was not declared in the scope

    #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"?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: 'fileMenu' was not declared in the scope

    Yeah... and? Where did you declare fileMenu?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2012
    Posts
    16
    Qt products
    Qt4

    Default Re: 'fileMenu' was not declared in the scope

    filemenu declare after
    QAction *newAct;
    and we can show this code
    QAction *newAct;
    QMenu *fileMenu;;
    THANK U FOR THE HELP)
    Last edited by lapdx; 27th November 2012 at 15:17.

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 'fileMenu' was not declared in the scope

    Quote Originally Posted by lapdx View Post
    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!
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. QAction *newAct; // What is this for??? you say fileMenu is declared after this...
    To copy to clipboard, switch view to plain text mode 

    please use CODE tags for code, not quotes!!
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: 'fileMenu' was not declared in the scope

    Atleast declare it now. or just include the header file here.
    Qt Code:
    1. QMenu *fileMenu;;
    To copy to clipboard, switch view to plain text mode 
    What is this then? Why are you using two semi colons here?

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: 'fileMenu' was not declared in the scope

    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.

Similar Threads

  1. glTexImage3D is not declared in the scope.
    By Elberion in forum Newbie
    Replies: 6
    Last Post: 26th June 2011, 07:15
  2. ui not declared in scope
    By steve.bush in forum Newbie
    Replies: 5
    Last Post: 19th March 2011, 08:58
  3. GetFileSizeEx was not declared in this scope
    By Threepwood in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2011, 12:03
  4. QDomDocument was not declared in this scope
    By grantbj74 in forum Newbie
    Replies: 5
    Last Post: 25th August 2009, 09:43
  5. Replies: 2
    Last Post: 28th December 2007, 18:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.