Results 1 to 8 of 8

Thread: Displaying Menu Bar

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Displaying Menu Bar

    Hi, I m using QtSDK 4.7 in my windows vista..
    I thought the following code is enough to show a menu bar..

    Qt Code:
    1. QAction *exitAct = new QAction(tr("E&xit"), this);
    2. connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
    3. QMenu *filemenu = new QMenu("&File", this);
    4. menuBar()->addMenu(filemenu);
    5. filemenu->addAction(exitAct);
    To copy to clipboard, switch view to plain text mode 

    This is included in the MainWindow constructor.
    But the menu bar is not being displayed. What else can i do?
    I ve developed a small Qt project and i want it to b given gui using QMainWindow tools.
    Plz Help me.

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

    Default Re: Displaying Menu Bar

    Please provide a minimal compilable example reproducing the problem.
    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
    Apr 2011
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Displaying Menu Bar

    Thank u for reply sir. Here is the complete code which i think should show a menubar and a file menu. Plz verify it.

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. class MainWindow : public QMainWindow
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. MainWindow(QWidget *parent = 0);
    12. };
    13.  
    14. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QMenu>
    4. #include <QMenuBar>
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent)
    8. {
    9. QAction *exitAct = new QAction(tr("E&xit"), this);
    10. connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
    11. QMenu *filemenu = new QMenu("&File", this);
    12. menuBar()->addMenu(filemenu);
    13. filemenu->addAction(exitAct);
    14. }
    To copy to clipboard, switch view to plain text mode 
    I want a simple code that should show menubar and menu items so that i can put actions for them. Thank u.

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

    Default Re: Displaying Menu Bar

    Does this minimal example work?
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv){
    4. QApplication app(argc, argv);
    5. QAction *exitAct = new QAction("Exit", &mw);
    6. QMenu *filemenu = new QMenu("File", &mw);
    7. mw.menuBar()->addMenu(filemenu);
    8. filemenu->addAction(exitAct);
    9. mw.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    If not, do other Qt applications (like some demos) show menus?
    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.


Similar Threads

  1. displaying .gif
    By sven-kt in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2009, 12:00
  2. Replies: 1
    Last Post: 28th July 2009, 06:58
  3. Displaying image
    By Rui in forum Newbie
    Replies: 1
    Last Post: 20th June 2009, 21:15
  4. GUI not displaying
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2007, 21:28
  5. QTAbBar not displaying
    By Dune in forum Qt Programming
    Replies: 17
    Last Post: 9th February 2006, 18:25

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
  •  
Qt is a trademark of The Qt Company.