Results 1 to 11 of 11

Thread: Using the menubar

  1. #1
    Join Date
    Feb 2006
    Location
    Germany
    Posts
    5
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Using the menubar

    Hi,
    in the menubar of my program i have a entry "new" and i want to use it to execute a function of mine, how would i do that?
    The function will change the value of some lineedits.
    i guess it will work with signals? but how i can execute my function?

    Thx for your help

    Steve

  2. #2
    Join Date
    Feb 2006
    Location
    Enschede, NL, EU
    Posts
    19
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Using the menubar

    Make sure the function you need executed is declared as a slot, and connect the Qpopupmenu's activated(int) signal to it and check the int for being the correct item...

    Better and more compatible with Qt4 is to use QAction objects which have their own signals per action...
    like so

    Qt Code:
    1. QAction *fileNewAction=new QAction("&New...", QKeySequence("Ctrl+N"),this);
    2. QPopupMenu *fileMenu=new QPopupMenu(this);
    3. fileNewAction->addTo(fileMenu);
    4. connect(fileNewAction,SIGNAL(activated()),this,SLOT(handleFileNew()));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Using the menubar

    Some strange question...What nkind of new item you have? QAction or QPopupMenu..for first you have answer from ReilenBlaeyze

    for QPopupMenu

    Qt Code:
    1. connect(newMenu,SIGNAL(activated(int)),this,SLOT(handleMenuActivate(int)));
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  4. #4
    Join Date
    Feb 2006
    Location
    Germany
    Posts
    5
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using the menubar

    First thx for the fast reply.

    Yes i thought i was doing it the right at least i tried it that way making a public slot writing my function there and try to use it but doesn't work the function itself works but when i want to connect it it just doesn't do anything.

    in my class i made a public slots: section with my function in it.

    Any ideas what i could have done wrong?

  5. #5
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Using the menubar

    Have you declare Q_OBJECT macros in header file?
    Show your code pls
    a life without programming is like an empty bottle

  6. #6
    Join Date
    Feb 2006
    Location
    Germany
    Posts
    5
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using the menubar

    #include <QtGui/QMainWindow>
    #include "ui_sudoku.h"

    class Sudoku : public QMainWindow
    {
    Q_OBJECT

    public:
    Sudoku(QWidget *parent = 0, Qt::WFlags flags = 0);
    ~Sudoku();

    public slots:
    void news();

    private:
    Ui::SudokuClass ui;



    };

  7. #7
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Using the menubar

    Yes its nice... but without implementation its hard give you your problem solving
    a life without programming is like an empty bottle

  8. #8
    Join Date
    Feb 2006
    Location
    Germany
    Posts
    5
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using the menubar

    What implementaion in the ui_sudoku.h i have it like
    QObject::connect(actionNew_game, SIGNAL(activated()), SudokuClass, SLOT(news()));

    what else you need?

  9. #9
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Using the menubar

    Its you need

    Code that creating and adding actions to your menu

    Have you see some messages, alike "could not connect bla bla bla" in debug window?
    a life without programming is like an empty bottle

  10. #10
    Join Date
    Feb 2006
    Location
    Germany
    Posts
    5
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using the menubar

    Hm funny now it works.
    Don't know what i changed really just compiled it again and now it works mh
    Thanks a lot for your help!

    but is it normal that i can't connect the signal to the slot in the "Signal slot editor"? It doesn't show my function in the "slot" window.

  11. #11
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Using the menubar

    It becouse your method doesnt have the same input parameters as signal
    a life without programming is like an empty bottle

  12. The following user says thank you to zlatko for this useful post:

    Steve (27th February 2006)

Similar Threads

  1. Moving menu to the right menubar corner
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2008, 05:24
  2. Showing and hiding menubar
    By borges in forum Newbie
    Replies: 1
    Last Post: 23rd September 2007, 10:56
  3. QActions don't work with menubar hidden
    By Pepe in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 01:04
  4. menuBar() Problem
    By Cutey in forum Qt Programming
    Replies: 9
    Last Post: 25th January 2007, 11:50
  5. Replies: 2
    Last Post: 12th November 2006, 08:47

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.