Problems with QMenu::addMenu
-
Welcome to devnet
Do you have any particular reason not using "addMenu":http://developer.qt.nokia.com/doc/qt-4.8/qmenu.html#addMenu ?
-
There is no such <code>QMenu::addAction(QAction action)</code> method because <code>QAction</code> is a <code>QObject</code> and thus cannot be passed as value.
The method you are looking for is <code>QMenu::addAction(QAction* action)</code>, which allows you to pass an already existing <code>QAction</code>. Be aware that the <code>QAction</code> has to be created on the heap. Do not pass a stack object!
-
Try something like this:
@QAction *myAction = new QAction(tr("&File"));
myAction->setShortcuts("Ctrl+F");
myAction->setStatusTip("Whatever you want...");
connect(myAction,SIGNAL(triggered()), this, SLOT(myFileFunction()));// ...
menu->addAction(myAction);@
-
If i call the QAction constructor in this way:
@
QAction aktOpen = new QAction(QObject::tr("&File"));
@
i get the following error message:
@
main.cpp:11: error: no matching function for call to 'QAction::QAction(QString)'
../../../QtSDK/Desktop/Qt/4.7.4/mingw/include/QtGui/qaction.h:236: note: candidates are: QAction::QAction(const QAction&)
../../../QtSDK/Desktop/Qt/4.7.4/mingw/include/QtGui/qaction.h:212: note: QAction::QAction(QActionPrivate&, QObject)
../../../QtSDK/Desktop/Qt/4.7.4/mingw/include/QtGui/qaction.h:103: note: QAction::QAction(const QIcon&, const QString&, QObject*)
../../../QtSDK/Desktop/Qt/4.7.4/mingw/include/QtGui/qaction.h:102: note: QAction::QAction(const QString&, QObject*)
../../../QtSDK/Desktop/Qt/4.7.4/mingw/include/QtGui/qaction.h:101: note: QAction::QAction(QObject*)
@ -
The signature of the "QAction constructor taking a QString as argument":/doc/qt-4.8/qaction.html#QAction-2 is quite clear:
@
QAction::QAction ( const QString & text, QObject * parent )
@The parent pointer is not optional, you have to pass a a value here. So you're not running into some const char * or QString issue, but a missing second argument here.