PDA

View Full Version : Displaying Menu Bar



giriuvce
21st May 2011, 08:44
Hi, I m using QtSDK 4.7 in my windows vista..
I thought the following code is enough to show a menu bar..


QAction *exitAct = new QAction(tr("E&xit"), this);
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
QMenu *filemenu = new QMenu("&File", this);
menuBar()->addMenu(filemenu);
filemenu->addAction(exitAct);

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.

wysota
22nd May 2011, 22:39
Please provide a minimal compilable example reproducing the problem.

giriuvce
24th May 2011, 07:43
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

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
};

#endif // MAINWINDOW_H

main.cpp

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMenu>
#include <QMenuBar>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QAction *exitAct = new QAction(tr("E&xit"), this);
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
QMenu *filemenu = new QMenu("&File", this);
menuBar()->addMenu(filemenu);
filemenu->addAction(exitAct);
}

I want a simple code that should show menubar and menu items so that i can put actions for them. Thank u.

wysota
24th May 2011, 09:40
Does this minimal example work?

#include <QtGui>

int main(int argc, char **argv){
QApplication app(argc, argv);
QMainWindow mw;
QAction *exitAct = new QAction("Exit", &mw);
QMenu *filemenu = new QMenu("File", &mw);
mw.menuBar()->addMenu(filemenu);
filemenu->addAction(exitAct);
mw.show();
return app.exec();
}
If not, do other Qt applications (like some demos) show menus?

giriuvce
24th May 2011, 14:27
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.

wysota
24th May 2011, 16:02
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.

giriuvce
25th May 2011, 05:59
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.

wysota
25th May 2011, 08:20
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