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. Link Menu Option to another window
Forum Updated to NodeBB v4.3 + New Features

Link Menu Option to another window

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 855 Views 1 Watching
  • 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
    Saltywaffles
    wrote on last edited by
    #1

    Hello,

    I am attempting to link a menu option to another window in QT. For example, in the menu bar, I have an option for "Rules Home". When the user clicks this, it should open the rules form that I have created. I was curious as to how I get the menu option to allow that to happen?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome to the forums.

      Do you mean from code or using the Designer?
      (both is possible)

      In any case, the menus use QAction so when you click on menu item
      its triggered() signal is emitted.

      So for anything to happen, you connect a slot to this signal and
      then create an instance of the other window and show it.

      https://doc.qt.io/qt-5/qtwidgets-mainwindows-menus-example.html

      1 Reply Last reply
      4
      • S Offline
        S Offline
        Saltywaffles
        wrote on last edited by
        #3

        Hello,

        I do mean in the creator. I managed to figure it out by using

        void Firewall::on_actionRules_Home_triggered()
        {
        Rules *w = new Rules;
        w->setAttribute(Qt::WA_DeleteOnClose);
        w->show();
        }

        1 Reply Last reply
        1
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Super you found the "Goto slot" feature.
          One note about that one.
          Its based on automatic match up using the widget name so after you used "goto slot"
          you should not rename the actionRules_Home as then it fails to
          auto connect. Nor should you rename the on_actionRules_Home_triggered function.

          The better solution is to use connect to do it manually as then you can get compile errors
          in case you renamed something.

          That said - for a small app with a few menu items, the auto connect is fine but in
          a multiple person project with an app having tons of menus and buttons, the auto connect is
          just too fragile in real life. At least thats my experience.

          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