Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Calling menu function in another form

[SOLVED] Calling menu function in another form

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 949 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sharon_obl82
    wrote on 25 Jun 2014, 07:18 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p3c0
      Moderators
      wrote on 25 Jun 2014, 07:59 last edited by
      #2

      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.

      157

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 25 Jun 2014, 08:17 last edited by
        #3

        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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sharon_obl82
          wrote on 26 Jun 2014, 01:12 last edited by
          #4

          thanks very much all!

          1 Reply Last reply
          0

          1/4

          25 Jun 2014, 07:18

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved