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. Qt Signal, std::function connection/reconnection at later date.
Forum Updated to NodeBB v4.3 + New Features

Qt Signal, std::function connection/reconnection at later date.

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 2.3k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Something is not clear, why are your actions tied to one specific toolbar in the first place ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dariusz
      wrote on last edited by
      #3

      Hmmm probably because I'm learning them in a probably backward way the more I use them now.... hmmmmmmmmmmmmm and I initially assumed that there is only 1 action and now Im reading that they are a bit more "universal" and I can have 1 action represented by multiple buttons mhmmmm

      But what I need is to link it to given toolbar to provide control over specific area of the app... hmm

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Than that makes that action even stranger because if I understand correctly, moving an action from one toolbar to another changes it area of effect which is likely something that's going to feel strange for your users.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • D Offline
          D Offline
          Dariusz
          wrote on last edited by
          #5

          Well, tricky. Imagine photoshop, you have the toolbar with brushes and so on. But in my case imagine that they instead directly adjust image. Lets say 1 button makes it bright, other contrasty. Now if user now creates another image, he can have another exclusive control panel for that iamge to do these things and if he has a custom script that he can drag on top of a panel. Now he can duplicate them and apply to another image... bit weird and tricky. Essentially I want to provide a toolbar that user can customize freely.

          mrjjM 1 Reply Last reply
          0
          • D Dariusz

            Well, tricky. Imagine photoshop, you have the toolbar with brushes and so on. But in my case imagine that they instead directly adjust image. Lets say 1 button makes it bright, other contrasty. Now if user now creates another image, he can have another exclusive control panel for that iamge to do these things and if he has a custom script that he can drag on top of a panel. Now he can duplicate them and apply to another image... bit weird and tricky. Essentially I want to provide a toolbar that user can customize freely.

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

            @Dariusz
            Hi
            But the commands (action) works the same regardless of image ?
            So When action X triggers, its a question of which image is the current/being processed and not so much the action have to call a different function ?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Dariusz
              wrote on last edited by
              #7

              Yes true in PS case. But in my case I will have separate "work" space for separate toolbars. And I want to allow user to move/copy tools from 1 toolbar to another. So the actions should relay on toolbar "parent" object and not their original connections.

              mrjjM 1 Reply Last reply
              0
              • D Dariusz

                Yes true in PS case. But in my case I will have separate "work" space for separate toolbars. And I want to allow user to move/copy tools from 1 toolbar to another. So the actions should relay on toolbar "parent" object and not their original connections.

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

                @Dariusz
                But its not the actual toolbar that handles the Trigger of the action so its a bit
                odd use case.
                But basically, when you move an Action, you want to disconnect it and then
                hook its trigger signal to slot in new/other work space ?

                Im not sure what you want to store in it with the std::function since it sounds like
                you can just disconnect and connect to the new slot ?

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Dariusz
                  wrote on last edited by
                  #9

                  Hey

                  Well, I need to store function, in order to reconnect it.

                  I can do something like

                  
                  myAction::myAction(QString text, QObject *objPtr, std::function<void()> functionPtr) : mObjPtr(objPtr), mFunction(functionPtr) {
                     connection =  connect(this, &QAction::triggered, objPtr, &mFunction);
                  }
                  
                     void myAction::reconnect(Object *objPtr){
                      disconnect(connection);
                      connection = connect(this, &QAction::triggered, objPtr, &mFunction);
                  mObjPtr=objPtr;
                  }
                  

                  This way I disconnect from old object, and reconnect to new object, using stored function pointer/ref/something again.

                  mrjjM 1 Reply Last reply
                  0
                  • D Dariusz

                    Hey

                    Well, I need to store function, in order to reconnect it.

                    I can do something like

                    
                    myAction::myAction(QString text, QObject *objPtr, std::function<void()> functionPtr) : mObjPtr(objPtr), mFunction(functionPtr) {
                       connection =  connect(this, &QAction::triggered, objPtr, &mFunction);
                    }
                    
                       void myAction::reconnect(Object *objPtr){
                        disconnect(connection);
                        connection = connect(this, &QAction::triggered, objPtr, &mFunction);
                    mObjPtr=objPtr;
                    }
                    

                    This way I disconnect from old object, and reconnect to new object, using stored function pointer/ref/something again.

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

                    @Dariusz
                    Hey
                    Ok. but say you have 3 toolbars. When you move the action around, wont it need to know all functions then, for all toolbars ?
                    Or do you just need to remember the last old method to reconnect to ?

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Dariusz
                      wrote on last edited by
                      #11

                      Humh.... just last one I would think. The toolbars are of the same class/type so they have the same functions. I would move from tolballX(nameA) to tolballX(nameB) essentially. The toolbar would hold a pointer to the active workspace.
                      And I would only need last method I think. The way it seems that I'm using the "actions" is to have individual instances of it per my workspace. I'm now thinking about mutliple toolbars per workspace but humhhhh then I could use that action mutliple toolbar icon linking. But I think it will be fine gotta test it out :- )

                      mrjjM 1 Reply Last reply
                      0
                      • D Dariusz

                        Humh.... just last one I would think. The toolbars are of the same class/type so they have the same functions. I would move from tolballX(nameA) to tolballX(nameB) essentially. The toolbar would hold a pointer to the active workspace.
                        And I would only need last method I think. The way it seems that I'm using the "actions" is to have individual instances of it per my workspace. I'm now thinking about mutliple toolbars per workspace but humhhhh then I could use that action mutliple toolbar icon linking. But I think it will be fine gotta test it out :- )

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

                        @Dariusz
                        ok. i think i get it even its a bit different use case that normally.
                        Happy programming then.

                        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