PDA

View Full Version : addMenu problem



nicolas1
17th March 2009, 09:21
Hello,

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

Any suggestion?



class PhotoWarperWindow : public QMainWindow
{
Q_OBJECT
}

PhotoWarperWindow::PhotoWarperWindow(void)
{
QWidget *widget = new QWidget;

setCentralWidget(widget);

QVBoxLayout *layout = new QVBoxLayout;

layout->setMargin(5);

widget->setLayout(layout);

//CreateActions();
CreateMenus();

setWindowTitle(QString::fromUtf8("Menus"));
setMinimumSize(160, 160);
resize(480, 320);
}

void PhotoWarperWindow::CreateMenus()
{
QMenuBar *mb = menuBar();

file_menu_ = new QMenu(menuBar());

menuBar()->addMenu(file_menu_); <- PROGRAM CRASH HERE
}


int main(int argc, char* argv[])
{
QApplication app(argc, argv);

PhotoWarperWindow window;

window.show();

return app.exec();
}

ComaWhite
17th March 2009, 09:25
Try it this way



fileMenu = menuBar()->addMenu(tr("&File"));


And look at this example
http://doc.trolltech.com/4.5/mainwindows-menus.html

nicolas1
17th March 2009, 09:37
Changed to:

file_menu_ = menuBar()->addMenu(tr("&File"));

Program does not get crashed here, but crashes later:


setWindowTitle(QString::fromUtf8("Menus"));

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

Last call from stack:
QCoreApplication::notifyInternal

spirit
17th March 2009, 09:44
could you post compilable example?

nicolas1
17th March 2009, 09:48
Solved!

Recompiled source file, where



int main(int argc, char* argv[])
{
QApplication app(argc, argv);

PhotoWarperWindow window;

window.show();

return app.exec();
}


And built app, problem cleared... ((