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. where should action execution happen?

where should action execution happen?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 542 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    i have a module like class, which is QObject.
    the module creates a lot of actions.
    i don't want to add as much slots in the module, instead i want to create a class which consists of only public slots, for each of the actions.
    i want to know if this is a good pattern to use

    JonBJ 1 Reply Last reply
    0
    • U user4592357

      i have a module like class, which is QObject.
      the module creates a lot of actions.
      i don't want to add as much slots in the module, instead i want to create a class which consists of only public slots, for each of the actions.
      i want to know if this is a good pattern to use

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @user4592357
      Slots would be best defined where the body of the code they execute is closest to the objects it needs to access. For example, if your slots spend a lot of their time accessing objects/widgets defined in your MainWindow class, it's all very well putting them elsewhere as you say but then you are likely to have parameters to them to access the MainWindow, and possibly its private variables. Which is not good.

      That is a separate question from whether you want to, say, derive your own class from QAction to use. As usual with Qt signals/slots, the module which creates a QAction and connect()s its signals to slots must simply have visibility of both the signals and the desired slot objects.

      U 1 Reply Last reply
      0
      • JonBJ JonB

        @user4592357
        Slots would be best defined where the body of the code they execute is closest to the objects it needs to access. For example, if your slots spend a lot of their time accessing objects/widgets defined in your MainWindow class, it's all very well putting them elsewhere as you say but then you are likely to have parameters to them to access the MainWindow, and possibly its private variables. Which is not good.

        That is a separate question from whether you want to, say, derive your own class from QAction to use. As usual with Qt signals/slots, the module which creates a QAction and connect()s its signals to slots must simply have visibility of both the signals and the desired slot objects.

        U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        @JonB
        i have main window pointer and add the actions to main window from the module, so I can't place the slots in main window.

        neither i want to place them in module.
        so i thought i would need to create a new class, actionExecutor or whatever

        JonBJ 1 Reply Last reply
        0
        • U user4592357

          @JonB
          i have main window pointer and add the actions to main window from the module, so I can't place the slots in main window.

          neither i want to place them in module.
          so i thought i would need to create a new class, actionExecutor or whatever

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @user4592357 said in where should action execution happen?:

          i have main window pointer and add the actions to main window from the module, so I can't place the slots in main window.

          Precisely! Which doesn't sound very good :) It sounds like you have a number of widgets with actions and slots to do stuff all of which belong in/access members in your main window class? In which case, trying to create some other module to offer the slots for the actions is likely to make it bad just as you are saying....

          U 1 Reply Last reply
          0
          • JonBJ JonB

            @user4592357 said in where should action execution happen?:

            i have main window pointer and add the actions to main window from the module, so I can't place the slots in main window.

            Precisely! Which doesn't sound very good :) It sounds like you have a number of widgets with actions and slots to do stuff all of which belong in/access members in your main window class? In which case, trying to create some other module to offer the slots for the actions is likely to make it bad just as you are saying....

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #5

            @JonB
            why is it bad? if my module is very smart thing, i may give it only to people who pay for it :)

            so it makes sense to add actions in module.

            so, should i create this new actionExecutor class and have public functions in it, and connect my actions to these functions?

            jsulmJ 1 Reply Last reply
            0
            • U user4592357

              @JonB
              why is it bad? if my module is very smart thing, i may give it only to people who pay for it :)

              so it makes sense to add actions in module.

              so, should i create this new actionExecutor class and have public functions in it, and connect my actions to these functions?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @user4592357 Usually a class which emits signals should not know anything about classes which connects to its signals. I suggest you provide an interface in your model to get the actions, then your main window can get these actions and connect to them - your model does not have to care about classes connecting to it.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2

              • Login

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