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. Connecting menu actions
Forum Updated to NodeBB v4.3 + New Features

Connecting menu actions

Scheduled Pinned Locked Moved General and Desktop
9 Posts 9 Posters 33.6k Views 3 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.
  • J Offline
    J Offline
    jza1
    wrote on last edited by
    #1

    Hi. I have a simple problem of creating and connecting functions to be attached to menu items.

    I found useful the Menus example bundled with QT Creator, but when using the Design tool it's a bit different. In ui_mainwindow.h it autocreates a class Ui_MainWindow while the example puts everything in the MainWindow class. So how would I connect the actions to the slots properly when using the Designer? If I define a private slot function in MainWindow class (mainwindow.h), it does not show up in the Signals & Slots editor.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Usually classes are defined this way (Qt Creator does that automatically for you):
      @
      // Recalling from memory... reality might be a tad different :)
      MainWindow : public QMainWindow, public Ui::MainWindow
      @

      (Z(:^

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Wilk
        wrote on last edited by
        #3

        Hello.
        The easiest way of connecting slots with signals of actions in menu:

        Create new action in designer.

        Add it into menu/toolbar/etc.

        Right click on it and choose "Go to slot"

        Signal and slot will be auto connected.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dexli
          wrote on last edited by
          #4

          [quote author="Wilk" date="1337774662"]Hello.
          The easiest way of connecting slots with signals of actions in menu:

          Create new action in designer.

          Add it into menu/toolbar/etc.

          Right click on it and choose "Go to slot"

          Signal and slot will be auto connected.[/quote]

          This did not work!

          if you right click on a menu item you only see
          insert devider
          delete action
          ( may be different strings because I use the german language)

          Also the use of F4 (edit Signal/Slots) is not usefull because in this way you only can select the menu itself and not the menu items

          The only thing that worked (for me) is using the action editor.
          selecting the action there and using the right button will allow to "display slot" selecting one and the editor open the according cpp file with a prototyp of the slot.

          osirisgothraO A 2 Replies Last reply
          0
          • B Offline
            B Offline
            Buckets
            wrote on last edited by
            #5

            I have a project where I used a ui_mainwindow.h.

            in order to connect the action you need to use
            @connect( ui -> some_action, SIGNAL(triggered()), qApp, SLOT(some slot))@

            ba ba ba
            ba na na na

            1 Reply Last reply
            0
            • D dexli

              [quote author="Wilk" date="1337774662"]Hello.
              The easiest way of connecting slots with signals of actions in menu:

              Create new action in designer.

              Add it into menu/toolbar/etc.

              Right click on it and choose "Go to slot"

              Signal and slot will be auto connected.[/quote]

              This did not work!

              if you right click on a menu item you only see
              insert devider
              delete action
              ( may be different strings because I use the german language)

              Also the use of F4 (edit Signal/Slots) is not usefull because in this way you only can select the menu itself and not the menu items

              The only thing that worked (for me) is using the action editor.
              selecting the action there and using the right button will allow to "display slot" selecting one and the editor open the according cpp file with a prototyp of the slot.

              osirisgothraO Offline
              osirisgothraO Offline
              osirisgothra
              wrote on last edited by
              #6

              @dexli
              The problem you are having is because you are clicking on the menu or toolbar items themselves. You have to click on the object created in the 'Actions' pane, usually on the side or bottom tool views. If you don't see this, right click on a toolbar area that is empty until you get the context menu that has a list of checkable items to view (or select Window->Views from the main menu). Ensure the 'Action Editor' is checked. You may have to uncheck it and recheck it to make it show up if it is hidden AND checked.

              To map the action's signals to a new slot functions automagically: Right click on any action and select 'go to slot' and double click 'triggered()' to create a function for it.

              To map signals directly to another object's existing slot: Ensure the "Signals and Slots Editor" toolwindow is visible using the same method mentioned above. Map the action to the signal, for example, from left to right (in the s&s editor), mapping the "Exit" menu item/action to the "close()" function of QMainWindow is simple as doing this: in the drop down boxes, left to right, pick "actionExit" under sender, then 'triggered()' under signal, and then 'MainWindow' under reciever, and 'close()' under slot. It's that easy :)

              *This example assumes a menu item named "Exit" created with that name initially, resulting in the auto name 'actionExit' and a window being used is a default main window with all the default settings. Adjust the parameters to suit your needs!!

              As of 3.4.1, there still is no direct 'wiring' of actions in the signals & slots editing interface (the red/blue lines on the widget itself). I think this a HUGE missing feature which for me makes that mode useless since more than half of my s&s editing involves actions. After all, what are most tasks initiated by users done from in a main UI window, that's right.. whether its a toolbar button or a menu item or statusbar or context menu, its AN ACTION. Why this wasn't included is... insert rant here. :) Hope that helps ease the pain and Im sorry it took 2 years to get a response from me (but hopefully new readers will be helped too). bye!

              I'm truly glad you r/offmychess t finally, but please don't go too far, because you r/beyondvoxels and that implies that u r/donewithlife. Oh well time to git back to the lab, because azure sea here, I have a lot of work to do...

              1 Reply Last reply
              2
              • D dexli

                [quote author="Wilk" date="1337774662"]Hello.
                The easiest way of connecting slots with signals of actions in menu:

                Create new action in designer.

                Add it into menu/toolbar/etc.

                Right click on it and choose "Go to slot"

                Signal and slot will be auto connected.[/quote]

                This did not work!

                if you right click on a menu item you only see
                insert devider
                delete action
                ( may be different strings because I use the german language)

                Also the use of F4 (edit Signal/Slots) is not usefull because in this way you only can select the menu itself and not the menu items

                The only thing that worked (for me) is using the action editor.
                selecting the action there and using the right button will allow to "display slot" selecting one and the editor open the according cpp file with a prototyp of the slot.

                A Offline
                A Offline
                Alok Sinha
                wrote on last edited by
                #7

                @dexli go to slot not showing triggered what to do

                Thank YouT mrjjM 2 Replies Last reply
                0
                • A Alok Sinha

                  @dexli go to slot not showing triggered what to do

                  Thank YouT Offline
                  Thank YouT Offline
                  Thank You
                  wrote on last edited by
                  #8

                  @Alok-Sinha

                  lmao (don't get offended guys)
                  After 8 years,
                  Now he will use this answer

                  Let's make QT free or It will go forever

                  TRUE AND FALSE <3

                  1 Reply Last reply
                  2
                  • A Alok Sinha

                    @dexli go to slot not showing triggered what to do

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Alok-Sinha

                    Are you clicking it right ?
                    alt text

                    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