Results 1 to 8 of 8

Thread: Displaying Menu Bar

  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,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: 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,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: 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.


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

    Default Re: Displaying Menu Bar

    Sir, This code is showing a white window as in the previous one.
    Examples which are given in the simulator about Main Window dont show Menu Bar and Menu Options.
    Except that i am getting other output. So may it b the problem with the simulator?


    Added after 1 5 minutes:


    Thank you very much for giving your time sir. This problem has beeb resolved. When
    the application is run in the simulator the menu options are not displayed in the mobile.
    That i can get in the "Qt Simulator Control" Wizard in the "Application" heading. Our basic code to show menu bar

    is running in simulator and in maemo emulator which i installed in my ubuntu.
    Last edited by giriuvce; 24th May 2011 at 13:27.

  6. #6
    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: Displaying Menu Bar

    Next time please don't forget to mention that you are running some application under Qt Simulator. That was the key part of your issue. Mobile devices don't show standard menus so the simulator doesn't show them as well.
    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.


  7. The following user says thank you to wysota for this useful post:

    giriuvce (25th May 2011)

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

    Default Re: Displaying Menu Bar

    Sorry for that sir.. But if mobile devices dont show standard menus, then we cant develop apps using menu for mobiles.
    Actually i wanted to show my Qt application as my Engineering project. I thought of telling that it can be used in mobile devices N900 etc. So then.. for that i should not use Menus. Sir please guide me by providing some material and some web links. Thank you very much for your help.

  9. #8
    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: Displaying Menu Bar

    Quote Originally Posted by giriuvce View Post
    Sorry for that sir.. But if mobile devices dont show standard menus, then we cant develop apps using menu for mobiles.
    That's not entirely true. But it is true that their menu system shouldn't be as large as for a desktop system for obvious reasons.

    Actually i wanted to show my Qt application as my Engineering project. I thought of telling that it can be used in mobile devices N900 etc. So then.. for that i should not use Menus. Sir please guide me by providing some material and some web links. Thank you very much for your help.
    http://doc.trolltech.com/qt-maemo-4.7/maemo5-menu.html
    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.


  10. The following user says thank you to wysota for this useful post:

    giriuvce (25th May 2011)

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.