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. QSignalWrapper uses wrong Method?
Forum Updated to NodeBB v4.3 + New Features

QSignalWrapper uses wrong Method?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 2.9k Views 1 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.
  • Q Offline
    Q Offline
    qohelet
    wrote on last edited by
    #3

    I'm coming right from Java (I was doing C++ years ago the last time...), so I assumed the Q*-Classes would all inherit from QObject. Now as I check it I see it's not like that.

    As shown in the code I have the slot:

    @ int addBtn(QIcon *icon = 0);@

    I just want to trigger this event (Parameter included) as someone clicks another button.
    How do I achieve that?

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

      Like I wrote before, a slot doesn't return anything.

      To have something clean, you should rather have a parameterless slot where you will implement the button creation logic.

      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
      • Q Offline
        Q Offline
        qohelet
        wrote on last edited by
        #5

        I know that a slot doesn't return anything, that's the reason why I used the QSignalMapper.
        But I don't know how to use it with a QIcon

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

          You can't do it with QSignalMapper. If I understand correctly when you click on that button a new one should be created with an icon, then what should happen ?

          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
          • Q Offline
            Q Offline
            qohelet
            wrote on last edited by
            #7

            So how can I do it? (Preferred not to subclass anything)

            Nothing, that's all.

            I just want to call the method addBtn(QIcon *icon) with the parameter if someone clicks a button.

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

              Like I said, do it indirectly. Have a parameterless slot where you will create the button retrieving the icon has you need it.

              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
              • Q Offline
                Q Offline
                qohelet
                wrote on last edited by
                #9

                That's the problem. I need to provide a Slot with a parameter. Otherwise I'd have done so already

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

                  What are the exact requirements ?

                  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
                  • Q Offline
                    Q Offline
                    qohelet
                    wrote on last edited by
                    #11

                    A slot with the parameter QIcon which creates a new Button with that QIcon and is called if you click something.

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

                      Directly, you can't have that. Qt's signals must be connected to slots with matching signatures or less (but still matching) parameters.

                      QSignalMapper works with either QString, QObjects, or QWidgets. So you can't have a slot with a QIcon * parameter. However and since there's chances that you build your icon using a path to an image file, you could use that to build your new button. But as i've stated before, your slots should not have any return type other than void.

                      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