[SOLVED] Passing menu event to another window
-
Hi,
I need some advice on this issue. I have two forms, lets say form A and form B. When i click on a menu event on form A, let's say 'New', I want to send this 'New' in text to form B to be displayed on a lineedit.
If i click on 'Open', it will instead displayed Open in the lineedit in form B.
Does anyone know how to do this?
Thank you. -
Hi,
You can connect "triggered":http://qt-project.org/doc/qt-5/qmenu.html#triggered signal of QAction on Form A to a slot of Form B and there you can update the LineEdit.
Some thing like this For Eg.
@
QMenu *menu = new QMenu(this);
menu->setStyleSheet(
"QMenu {"
"padding: 1px;"
"min-width: 3em;"
"min-height: 2px;"
"background-color: rgba(50, 50, 50, 50);"
"border: 1px solid gray;"
"}""QMenu::item {" "color: white;" "}" "QMenu::item:selected { " "background-color: rgb(153,215,255,80);" "}" ); QAction *newDoc; newDoc = new QAction(tr("New"), this); connect(newDoc, SIGNAL(triggered()), formB, SLOT(updateLineEdit())); //formB is Form B class's object and updateLineEdit is the respective slot of its menu->addAction(newDoc);
@
-
is this correct?
@
RadioWindow rw; //object from form B
QAction *newDoc = new QAction(tr("New"), this);
connect(newDoc, SIGNAL(triggered()), rw, SLOT(ui->lineEdit_6->setText("New"));myMenu.addAction(newDoc);
@I get compilation error :
expected ')' before ';' token -
ok, fixed it. Is this correct?
In form A:
@
QMenu myMenu;
RadioWindow *rw; //object from form B
QAction *newDoc = new QAction(tr("New"), this);
connect(newDoc, SIGNAL(triggered())), rw, SLOT(rw.setvalue());myMenu.addAction(newDoc);
@
in Form B
@
void RadioWindow::setvalue()
{
ui->lineEdit_6->setText("New");}
@I still get compile error saying "No matching function for call to MainWindow::connect .."
What am I missing here please?
-
@SLOT(rw.setvalue());@
just keep it as
@SLOT(setValue())@Be sure that setValue has been declared as a SLOT in RadioWindow.
Also seeing your this code:
@
RadioWindow *rw; //object from form B
@you must create a new object for RadioWindow.
-
thanks all, managed to solve my problem :)