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] Passing menu event to another window

[SOLVED] Passing menu event to another window

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 1.4k 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 last edited by
    #1

    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
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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
      0
      • S Offline
        S Offline
        sharon_obl82
        wrote on last edited by
        #3

        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
        0
        • jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by
          #4

          [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
          0
          • S Offline
            S Offline
            sharon_obl82
            wrote on last edited by
            #5

            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
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              @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
              0
              • S Offline
                S Offline
                sharon_obl82
                wrote on last edited by
                #7

                thanks all, managed to solve my problem :)

                1 Reply Last reply
                0

                • Login

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