Results 1 to 4 of 4

Thread: Android: menuBar()->addAction broken?

  1. #1
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Android: menuBar()->addAction broken?

    Hi,
    I want to have a clickable menu item that exits the app without having to open a subMenu.

    1. Actions added with menuBar().addAction() are *not* added/displayed in Qt5.3.1 on Android 2.3.1
    2. A connection between a subMenu's menuAction() signal and some closing slot returns a "true" but never fires.


    A small compileable example:
    #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

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

  2. #2
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Android: menuBar()->addAction broken?

    Attached you find the example project that demonstrates the problem.

    No ideas anyone?
    Attached Files Attached Files

  3. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default 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.
    Last edited by adutzu89; 19th July 2014 at 11:50.

  4. #4
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default 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.

Similar Threads

  1. Replies: 4
    Last Post: 10th July 2014, 16:22
  2. How do you make android applications display correctly on android phone?
    By Cyrebo in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 17th August 2013, 08:31
  3. using invokeMethod for menu addAction
    By dwizard in forum Newbie
    Replies: 1
    Last Post: 27th June 2013, 07:31
  4. QMenu and addAction problem
    By .:saeed:. in forum Newbie
    Replies: 0
    Last Post: 20th January 2011, 10:04
  5. Replies: 4
    Last Post: 16th September 2010, 17:24

Tags for this Thread

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.