Unsolved Qt Signal, std::function connection/reconnection at later date.
-
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
-
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.
-
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.
-
@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 ? -
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.
-
@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 ? -
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.
-
@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 ? -
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 :- ) -
@Dariusz
ok. i think i get it even its a bit different use case that normally.
Happy programming then.