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. Overloading signal possible? Or adding new signals to base classes?
Forum Update on Monday, May 27th 2025

Overloading signal possible? Or adding new signals to base classes?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 11.5k 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.
  • T Offline
    T Offline
    theuser
    wrote on last edited by
    #1

    Hello, recently i created a widget with QT designer.
    This widget contains some spinboxes as well as a child widget. Now i want the spinboxes to tell the child widget two things:
    a) that their value changed to int i and b) their own id(so the child widget knows which spinbox emitted the signal) thus i need a signal thats similar to this: void valueChanged(int,int). Of course normal spinboxes dont have such a thing so i wondered if it is possible to either change the signal or to add another signal which does the things i descriped.
    Thank you for any help :)

    1 Reply Last reply
    0
    • I Offline
      I Offline
      iunknwn
      wrote on last edited by
      #2

      You can tell which slider sent the signal to the child widget.

      In the slot of the child widget call QObject::sender() to find out.

      Alternately look into QSignalMapper.

      Vista x64 with Qt 4.8.2 and VS2010

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        adding signals to existing Qt classes is not possible. You can derive from them to achieve that, but I also suggest to use the existing signal and QObject::sender to get the originator of the signal. Then you can connect all spinboxes to one signal

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • B Offline
          B Offline
          baysmith
          wrote on last edited by
          #4

          Here are some code snippets for what iunknwn was describing.

          Setup spinboxes
          @
          m_spinbox1 = new QSpinBox(this);
          m_spinbox2 = new QSpinBox(this);
          m_spinbox3 = new QSpinBox(this);

          connect(m_spinbox1, SIGNAL(valueChanged(int)), this, SLOT(onChanged(int)));
          connect(m_spinbox2, SIGNAL(valueChanged(int)), this, SLOT(onChanged(int)));
          connect(m_spinbox3, SIGNAL(valueChanged(int)), this, SLOT(onChanged(int)));
          @

          Use sender() to identify spinbox
          @
          void onChanged(int value)
          {
          QSpinBox spinBox = qobject_cast<QSpinBox>(sender());
          if (spinBox == m_spinBox1) ...
          else if (spinBox == m_spinBox1) ...
          else if (spinBox == m_spinBox1) ...
          }
          @

          Nokia Certified Qt Specialist.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            theuser
            wrote on last edited by
            #5

            thank you for your fast answer, i changed my program accordingly, but now im getting this "error"(the program still compiles but the connections wont work):

            "No such slot QWidget::statChanged(int) in ./ui_mainwindow.h:211
            Object::connect: (sender name: 'Stat1Box')
            Object::connect: (receiver name: 'widget')"

            I created an extra class to draw within widget and told QT designer to use the class for the widget(that part works). But when i added Slots to said class(and connected the value change from my spinboxes with some of the slots) i got this error.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              baysmith
              wrote on last edited by
              #6

              Check that the slots are declared properly, connected properly, and that the build ran moc on the class.

              Nokia Certified Qt Specialist.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                If you defined the slots in the ui file (grafically) you have to add them by hand to your widget :-)

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  theuser
                  wrote on last edited by
                  #8

                  Ok i fixed it.
                  At first i had used the QT designer connector to connect the spinboxes with the child widget, but this didnt work(i dont know why, maybe i didnt tell the program properly that the child widget actually is a child).
                  Then i did it manually via connect(ui->spinbox,...,ui->widget...)
                  that worked.
                  thank you all :)

                  How do i tell QT that i created a child widget when using the desiger to create it? I just placed one within the original widget form and thought it is automatically a child, but this might not be true.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #9

                    This is true.
                    If you place widgets on other widgets in designer, they will become child widgets.
                    You can check that in the code, that is created from the designer .ui file: XXX_ui

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    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