Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] Passing menu event to another window

    General and Desktop
    3
    7
    1151
    Loading More Posts
    • 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
      sharon_obl82 last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators last edited by

        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);
        

        @

        157

        1 Reply Last reply Reply Quote 0
        • S
          sharon_obl82 last edited by

          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

          1 Reply Last reply Reply Quote 0
          • jeremy_k
            jeremy_k last edited by

            [quote author="sharon_obl82" date="1403055671"]
            @
            connect(newDoc, SIGNAL(triggered()), rw, SLOT(ui->lineEdit_6->setText("New"));
            @

            [/quote]

            Count the () pairs. There's a ) missing immediately before the ;

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply Reply Quote 0
            • S
              sharon_obl82 last edited by

              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?

              1 Reply Last reply Reply Quote 0
              • p3c0
                p3c0 Moderators last edited by

                @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.

                157

                1 Reply Last reply Reply Quote 0
                • S
                  sharon_obl82 last edited by

                  thanks all, managed to solve my problem :)

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post