Results 1 to 10 of 10

Thread: menuBar() Problem

  1. #1
    Join Date
    Dec 2006
    Location
    Bangalore, India
    Posts
    38
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question menuBar() Problem

    Hi Buddies,
    In my application I need to disable and enable the "MenuBar" in some circumstance. I am facing a problem( application crash ) while enabling "MenuBar".

    Here is the code snippet:
    Qt Code:
    1. void DWCMainWindow::setMainMenu( bool setCondn ) {
    2. menuBar()->setEnabled ( setCondn );
    3. }
    To copy to clipboard, switch view to plain text mode 
    Note :
    I am not facing any problem while disables the MenuBar.

    Any Help...
    Thanks in Advance.
    WINNERS DON`T D DIFFERENT THINGS THEY D THINGS differently.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: menuBar() Problem

    whats the error that you are getting ??

  3. #3
    Join Date
    Dec 2006
    Location
    Bangalore, India
    Posts
    38
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: menuBar() Problem

    It is not showing any error. Just it crashes the application.
    WINNERS DON`T D DIFFERENT THINGS THEY D THINGS differently.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: menuBar() Problem

    i tried enabling / disabling menubar with some button click on tool bar...
    it working fine for me...
    can u reproduce some code that gives your error ??

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: menuBar() Problem

    Maybe you are trying to access the menubar by the time it has not yet been constructed or has already been destructed? Add a check if QMainWindow::menuBar() happens to return NULL and/or run your application through a debugger and post the backtrace/callstack.
    J-P Nurmi

  6. #6
    Join Date
    Dec 2006
    Location
    Bangalore, India
    Posts
    38
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: menuBar() Problem

    Hi Aamer4yu,

    Me too tried a sample code to enable/disable menubar with some button click, it worked fine.
    But in my project I couldnt figure out the problem. I suspect the problem with loading back the menu item in the menubar.

    Any more Idea plz send word.

    Hi JPN,

    As you said,I have tried the following code
    Qt Code:
    1. void DWCMainWindow::setMainMenu( bool setCondn ) {
    2. QMenuBar* mnu = menuBar();/*This line causes the crash, while enable menuBar() returns NULL.*/
    3. mnu->setEnabled ( setCondn );
    4. }
    To copy to clipboard, switch view to plain text mode 
    plz tell me the wrokaround. Waiting for your Help.

    Thanks for your interest guys
    WINNERS DON`T D DIFFERENT THINGS THEY D THINGS differently.

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: menuBar() Problem

    Dont know why your application is crashing.. I tried the menu with QMenuBar pointer too... and its still working fine for me...
    also from source code, menuBar creates a menubar if it doesnt exist..

    Qt Code:
    1. QMenuBar *QMainWindow::menuBar() const
    2. {
    3. QMenuBar *menuBar = qobject_cast<QMenuBar *>(d_func()->layout->menuBar());
    4. if (!menuBar) {
    5. QMainWindow *self = const_cast<QMainWindow *>(this);
    6. menuBar = new QMenuBar(self);
    7. self->setMenuBar(menuBar);
    8. }
    9. return menuBar;
    10. }
    To copy to clipboard, switch view to plain text mode 

    I suggest one thing... catch the closEvent for your window... and trace back as to what caused it... it will give an idea why ur program is crashing...

    by the way, by your crash, I guess it means ur application closes without any error ?? right ?

  8. #8
    Join Date
    Jan 2007
    Location
    Augsburg, Germany
    Posts
    75
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: menuBar() Problem

    What about building your application and Qt in debug mode and stepping through?
    (hope thats not too difficult for you)

  9. #9
    Join Date
    Dec 2006
    Location
    Bangalore, India
    Posts
    38
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: menuBar() Problem

    Quote Originally Posted by aamer4yu View Post
    I suggest one thing... catch the closEvent for your window... and trace back as to what caused it... it will give an idea why ur program is crashing...

    by the way, by your crash, I guess it means ur application closes without any error ?? right ?
    Hi Gri,
    Quote Originally Posted by gri View Post
    What about building your application and Qt in debug mode and stepping through?
    What do you mean ? I couldnt understand ..?

    Hi Aamer4yu,

    My application constructs under Qt 3.3.4 on Windows XP.
    While trace I got the following error.
    "Unhandled exception in xxxxxx.exe: Access Violation" ://QMenuBar* mnu = menuBar(); is raising this error. menuBar() returns NULL value. How to handle that case.?

    It became hectic to me.. Please help me..
    WINNERS DON`T D DIFFERENT THINGS THEY D THINGS differently.

  10. #10
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: menuBar() Problem

    I am not famliar with Qt 3...

    neways I have few doubts...
    1) where are you calling setMainMenu() function ??
    2) what is mainwindow derived from ?
    3) are u trying to enable / disable menu from setMainMenu function, or are u tryung to create a menu ??

    rest i agree with gri.... u should step thru ur code...
    ie. moving line by line in ur code, while debugging it...

    also can u post a minimal example showing the problem u r facing ?

Similar Threads

  1. Replies: 2
    Last Post: 12th November 2006, 08:47
  2. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  3. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.