[SOLVED] Calling menu function in another form
-
wrote on 25 Jun 2014, 07:18 last edited by
Hi, I need advice on this issue. Basically I'd like to call Report function in mainwindow.cpp from another form called radiowindow.cpp to display out Report window.
radiowindow.cpp:
@QString value;
void RadioWindow::on_actionReport_triggered()
{
value = "Radio";
MainWindow report;
report.getvalue(value);
report.on_actionReport_triggered();}
@I have a get value from radiowindow.cpp in mainwindow.cpp
mainwindow.cpp:
@QString gvalue;
void MainWindow::getvalue(QString valuereceived)
{
gvalue =valuereceived;
}void MainWindow::on_actionReport_triggered()
{tablevalue = gvalue; qDebug() << "tablevalue in report is" << tablevalue; if (tablevalue == "Radio") { report =new Reportwindow(this); report->setWindowIcon(QIcon(":/icons/qt-icon80.ico")); report->setWindowTitle("Radio - User Configuration Manager"); qDebug() << "enter if" << tablevalue; report->show(); } else if (tablevalue == "Radio User") { ruser_report =new radiouser_report(this); ruser_report->setWindowIcon(QIcon(":/icons/qt-icon80.ico")); ruser_report->setWindowTitle("Radio User - User Configuration Manager"); ruser_report->show(); }
}
@
I can't seem to be able to display the report form :( what am i missing here?
-
bq. I can’t seem to be able to display the report form :( what am i missing here?
That is because the MainWindow object gets destroyed as soon as the function exits.
@
void RadioWindow::on_actionReport_triggered()
{
value = "Radio";
MainWindow report;
report.getvalue(value);
report.on_actionReport_triggered();}
@Create the MainWindow object on heap using the new keyword.
-
Hi,
There's also a flow in your program logic: MainWindow creates a new RadioWindow which creates a MainWindow. These two MainWindow are not the same.
I would recommend first taking a look at the signal and slot chapters and examples
-
wrote on 26 Jun 2014, 01:12 last edited by
thanks very much all!
1/4