Let me guess... If you modified the application example you should have the following:
//mainwindow.h
//[SKIP]
{
Q_OBJECT
public:
MainWindow();
//[SKIP]
private slots:
void newFile();
//[SKIP]
void documentWasModified();
void indexEnv(); // (1)
private:
void createActions();
//[SKIP]
QMenu *yourOwnMenu;
// (3) //[SKIP]
QAction *showYourOwnMenuAction;
// (2) };
//mainwindow.cpp
//[SKIP]
void MainWindow::createActions()
{
//[SKIP]
showYourOwnMenuAction
= new QAction(tr
("Show Preview Window"),
this);
// (2) showYourOwnMenuAction->setStatusTip(tr("Show Preview Window from the <i>Windows flags</i> example"));
connect(showYourOwnMenuAction, SIGNAL(triggered()), this, SLOT(indexEnv())); // (5)
//[SKIP]
}
void MainWindow::createMenus()
{
//[SKIP]
yourOwnMenu = menuBar()->addMenu(tr("&Your Menu")); // (3)
yourOwnMenu->addAction(showYourOwnMenuAction); // (4)
//[SKIP]
}
//mainwindow.h
//[SKIP]
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
//[SKIP]
private slots:
void newFile();
//[SKIP]
void documentWasModified();
void indexEnv(); // (1)
private:
void createActions();
//[SKIP]
QMenu *editMenu;
QMenu *helpMenu;
QMenu *yourOwnMenu; // (3)
//[SKIP]
QAction *aboutAct;
QAction *aboutQtAct;
QAction *showYourOwnMenuAction; // (2)
};
//mainwindow.cpp
//[SKIP]
void MainWindow::createActions()
{
//[SKIP]
showYourOwnMenuAction = new QAction(tr("Show Preview Window"), this); // (2)
showYourOwnMenuAction->setStatusTip(tr("Show Preview Window from the <i>Windows flags</i> example"));
connect(showYourOwnMenuAction, SIGNAL(triggered()), this, SLOT(indexEnv())); // (5)
//[SKIP]
}
void MainWindow::createMenus()
{
//[SKIP]
yourOwnMenu = menuBar()->addMenu(tr("&Your Menu")); // (3)
yourOwnMenu->addAction(showYourOwnMenuAction); // (4)
//[SKIP]
}
To copy to clipboard, switch view to plain text mode
To achieve the result you need you should do these steps:
- Implement your indexEnv() as a slot, so that you can connect() to it
- Create a QAction, which is to be triggered() when the user clicks on the corresponding menu item
- Create the menu itself
- Make your action available through the menu
- connect() the QAction's triggered() signal to your MainWindow's indexEnv() slot
Bookmarks