Android: menuBar()->addAction broken?
Hi,
I want to have a clickable menu item that exits the app without having to open a subMenu.
- Actions added with menuBar().addAction() are *not* added/displayed in Qt5.3.1 on Android 2.3.1
- A connection between a subMenu's menuAction() signal and some closing slot returns a "true" but never fires.
A small compileable example:
Quote:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void endMe();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
und
Quote:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMenuBar>
#include <QDebug>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
menuBar()->setNativeMenuBar(true);
menuBar()->setEnabled(true);
ui->setupUi(this);
//Not visible with Android
QAction* directAct=menuBar()->addAction("DirectA",this,SLOT(endMe()));
directAct->setVisible(true);
directAct->setEnabled(true);
//Visible but not firing
QMenu* directMenu=menuBar()->addMenu("DirectM");
directMenu->setEnabled(true);
connect(directMenu->menuAction(),SIGNAL(triggered()),this,SLOT(endMe( )));
//Visible, working (but one more click)
QMenu* normalMenu=menuBar()->addMenu("Normal");
QAction* normalActA=normalMenu->addAction("A",this,SLOT(endMe()));
QAction* normalActB=normalMenu->addAction("B",this,SLOT(endMe()));
normalMenu->setEnabled(true);
normalActA->setEnabled(true);
normalActB->setEnabled(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::endMe()
{
QMessageBox::about(this,"End","App will close now");
QApplication::quit();
}
It works on Windows, it doesn't on Android. Any ideas?
5 Attachment(s)
Re: Android: menuBar()->addAction broken?
Attached you find the example project that demonstrates the problem.
No ideas anyone?
Re: Android: menuBar()->addAction broken?
I don't seem to find a QMenuBar into your project, neither in designer, or code.
I am not an expert, but I use menubars in the following way.
//create menubar
QMenuBar *menuBar=new QMenuBar(this);
//create menu
QMenu *menu=new QMenu(tr("Menu'),this);
//create action
QAction *action=new QAction(tr("Action"),this);
//connect action signal to slot
connect(action,SIGNAL(triggered()),this,SLOT(SLOT( endMe()));
//add action to menu
menu->addAction(action);
//add menu to menubar
menuBar->addMenu(menu);
//set menubar to mainwindow
setMenuBar(menuBar);
Also worth mentioning QMenuBar is not visible in Android, but if you tap on the menu\option "button" on the device it should popup the menus.
Re: Android: menuBar()->addAction broken?
Thank you for your answer! I use the MenuBar that is provided by QMainWindow. I have tried subclassing it to catch the mousePress / mouseRelease event, but it seems to be an event key "43" that triggers the menuBar. After using that to do what I want, the MenuBar is be unusable until the program has been ended and restarted. Weird thing. I've actually given up here.