Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Where to implement custom slot for normal widget?
I have read much documentation, and haven't found what I need. I have a simple QLineEdit to which I added a custom slot in Designer. I connected a signal to it, great!
Now, where/how do I actually implement this custom slot? I see it being connected in my ui.h, but I simply don't know where I have to define the method.
Thank you in advance.
I need a custom slot per widget because, each widget calculates a different formula.
I wasn't building any widget :)
Anyways, after brainstorming a bit, I think I will go in the most gynormous if direction. I'll probably build a map<QString, vector<QString> > and read the widgets formulas from a text file. I already save/load every widget value in a map<QString,QString>, so it will fit my current "model".
Something along those lines anyways.
Then why not have a specialized class that does the formulas processing, have your slots there and just connect the QLineEdit editingFinished signal to the correct slot ?
By the way, since it sounds like you are doing math, are you sure QLineEdit is the best widget for your input ?
Yes! Much much much nicer!
Now I could go about it another way, and I'm thinking out loud here. Since all my lineedits are currently emitting editingFinished() to 1 slot only (it is the slot that updates my map of their values, used to save the document), then I could simply call the correct calculation function and update the value (and tooltip) there.
Not sure what is best, connecting the singals to other slots, or using my existing "master slot", since I need other values for my calculations. But this is definitely the best way I can foresee right now. Thank you so much for helping me figuring this out!
I posted this hoping to get input from more experienced developers on what is the best way to achieve my goal cleanly, and consider me a happy user :)
Actually its not complex math at all. Simply that a a lot of the outputs are readOnly text edits that depend on many other lineedits the user fills in. I guess its a fancy spreadsheet type thing, that is highly optimized for one use case only.
Unless I'm wrong, with your master slots you need to know which line edit emitted the signal, so if you change your QLineEdit for something else, you'll have to also modify your master, which is not really clean.
Also, rather than readonly QLineEdit, you should consider QLabel. Generally speaking, a user will search how to he can modify the content of a QLineEdit. A QLabel states clearly that it's read-only