Results 1 to 5 of 5

Thread: addMenu problem

  1. #1
    Join Date
    Jun 2008
    Posts
    35
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default addMenu problem

    Hello,

    Seems trivial problem, but do not understand why this happens?
    Simple program crashes on " menuBar()->addMenu(file_menu_); "

    Any suggestion?

    Qt Code:
    1. class PhotoWarperWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4. }
    5.  
    6. PhotoWarperWindow::PhotoWarperWindow(void)
    7. {
    8. QWidget *widget = new QWidget;
    9.  
    10. setCentralWidget(widget);
    11.  
    12. QVBoxLayout *layout = new QVBoxLayout;
    13.  
    14. layout->setMargin(5);
    15.  
    16. widget->setLayout(layout);
    17.  
    18. //CreateActions();
    19. CreateMenus();
    20.  
    21. setWindowTitle(QString::fromUtf8("Menus"));
    22. setMinimumSize(160, 160);
    23. resize(480, 320);
    24. }
    25.  
    26. void PhotoWarperWindow::CreateMenus()
    27. {
    28. QMenuBar *mb = menuBar();
    29.  
    30. file_menu_ = new QMenu(menuBar());
    31.  
    32. menuBar()->addMenu(file_menu_); <- PROGRAM CRASH HERE
    33. }
    34.  
    35.  
    36. int main(int argc, char* argv[])
    37. {
    38. QApplication app(argc, argv);
    39.  
    40. PhotoWarperWindow window;
    41.  
    42. window.show();
    43.  
    44. return app.exec();
    45. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: addMenu problem

    Try it this way

    Qt Code:
    1. fileMenu = menuBar()->addMenu(tr("&File"));
    To copy to clipboard, switch view to plain text mode 

    And look at this example
    http://doc.trolltech.com/4.5/mainwindows-menus.html
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  3. #3
    Join Date
    Jun 2008
    Posts
    35
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: addMenu problem

    Changed to:
    Qt Code:
    1. file_menu_ = menuBar()->addMenu(tr("&File"));
    To copy to clipboard, switch view to plain text mode 

    Program does not get crashed here, but crashes later:

    Qt Code:
    1. setWindowTitle(QString::fromUtf8("Menus"));
    To copy to clipboard, switch view to plain text mode 

    Surely, I checked "Menus" sample and made same code... But program get crashed

    Last call from stack:
    QCoreApplication::notifyInternal
    Last edited by nicolas1; 17th March 2009 at 09:44.

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: addMenu problem

    could you post compilable example?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Jun 2008
    Posts
    35
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: addMenu problem

    Solved!

    Recompiled source file, where

    Qt Code:
    1. int main(int argc, char* argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. PhotoWarperWindow window;
    6.  
    7. window.show();
    8.  
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    And built app, problem cleared... ((

Similar Threads

  1. Replies: 19
    Last Post: 3rd April 2009, 23:17
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  3. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  4. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  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.