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.2k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 26 Jun 2018, 14:32 last edited by
    #1

    Hey

    I'm trying to figure out how I can "update" my signals depending on their parent.

    Esentially I have 2 QToolBar(A and B) widgets and 2 QGraphicsView(A and B), Each widget controls their own views A A and B B.

    Now I have implemented a drag function to allow for the QToolButton's /Actions to be dragged from 1 toolBar to another.

    However if I am to drag buttonX from toolbarA to toolbarB & press it, the action still get sends to toolbarA. So I figured, I can store the obj ptr and function ptr during function creation & when I do a drop event and I finish reparrenting, I could call for disconnect() and then connect() again using new objPtr. As the functionPtr remain thesame all I have to do is reuse it from header...

    So my question is, how can I create the constructor/member object to properly store the data ?

    code of where I am at:

    myAction.h

    class myAction :public QAction{
        std::function<void()> mFunction;
        QObject *mObjPtr;
      public:
      myAction(QString text, QObject *objPtr, std::function<void()> functionPtr);
        void reconnect(Object *objPtr);
    
    }
    

    myAction.cpp

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

    Usage : addAction(new icAction("action a", this, &myToolBar::printTest));

    Any help would be awesome :- )

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 26 Jun 2018, 17:41 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 26 Jun 2018, 19:59 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 26 Jun 2018, 20:00 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 26 Jun 2018, 21:13 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.

            M 1 Reply Last reply 26 Jun 2018, 21:20
            0
            • D Dariusz
              26 Jun 2018, 21:13

              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.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 26 Jun 2018, 21:20 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 26 Jun 2018, 22:06 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.

                M 1 Reply Last reply 26 Jun 2018, 22:27
                0
                • D Dariusz
                  26 Jun 2018, 22:06

                  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.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 26 Jun 2018, 22:27 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 26 Jun 2018, 22:37 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.

                    M 1 Reply Last reply 26 Jun 2018, 22:45
                    0
                    • D Dariusz
                      26 Jun 2018, 22:37

                      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.

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 26 Jun 2018, 22:45 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 26 Jun 2018, 23:00 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 :- )

                        M 1 Reply Last reply 26 Jun 2018, 23:11
                        0
                        • D Dariusz
                          26 Jun 2018, 23:00

                          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 :- )

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 26 Jun 2018, 23:11 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

                          1/12

                          26 Jun 2018, 14:32

                          • Login

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