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 to implement custom slot for normal widget?

Where to implement custom slot for normal widget?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.3k Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello,

    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.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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.

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

        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 ?

        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
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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.

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

            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

            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

            • Login

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