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. Non-existing parameter during signal slots connection

Non-existing parameter during signal slots connection

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.7k 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.
  • Y Offline
    Y Offline
    yc2986
    wrote on last edited by
    #1

    Hello Qt Forum,

    I am designing a Qwt based plotting widget and I would like to write a customized legend widget that can display/hide the curves and change the curve color. The legend box looks like this.

    alt text

    For each item in this colored QComboBox it is set to QColor object via QCombobox::model()->setData(const QModelIndex, const QVariant, int role); method. So for each combobox value change I would like to send which QColor object is selected and connect to a void setColor(QColor &color) slot inside the curve class.

    I am a little bit confused on how to implement this signal inside my legend box widget class. Any suggestion will be appreciated here.

    Thanks!

    jsulmJ 1 Reply Last reply
    0
    • Y yc2986

      Hello Qt Forum,

      I am designing a Qwt based plotting widget and I would like to write a customized legend widget that can display/hide the curves and change the curve color. The legend box looks like this.

      alt text

      For each item in this colored QComboBox it is set to QColor object via QCombobox::model()->setData(const QModelIndex, const QVariant, int role); method. So for each combobox value change I would like to send which QColor object is selected and connect to a void setColor(QColor &color) slot inside the curve class.

      I am a little bit confused on how to implement this signal inside my legend box widget class. Any suggestion will be appreciated here.

      Thanks!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @yc2986 See http://doc.qt.io/qt-5/qcombobox.html#currentIndexChanged. You can connect this signal to your own slot. In that slot you get the color (http://doc.qt.io/qt-5/qcombobox.html#itemData) from the combo-box using the index provided by the signal and then you can do what ever you need to do with this color.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Y Offline
        Y Offline
        yc2986
        wrote on last edited by
        #3

        Thanks @jsulm for the information. I am digging around the signal-slots model in Qt for some time but I am still confused. Since in Qt the connected signal and slot should has the valid matching parameters.

        In this case probably I need a currentIndexChanged(int) signal and a setColor(int) slot according to your recommendation. And I am supposed to use the QComboBox::itemData(int index, int role) method in my setColor(int) slot to retrieve the color object selected. Here comes the confusing point. In order to access the QComboBox::itemData(int, int) method I need a QComboBox object.

        However what I passed from signal to slot is merely a int index variable indicating which number of item in the list I have selected. It seems to me that I need to pass a QObject from signal to slots as well in order to make things work.

        I think I have a lot of misunderstandings on how signal and slot works. Could you please point out what is wrong in my above statement? Thank you very much!

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

          Hi
          In a slot, you can get the widget that send the signal
          using the sender() function.
          Its is however always a QWidget QObject so you must try cast to the type
          to get full access. ( to get the right type)
          Like
          void mainwin::currentIndexChanged( int index) {
          QComboBox * cb= qobject_cast<QComboBox * > ( sender() )
          if (cb) {
          cb->itemData xxx
          }
          }

          This makes it possible to have mutiple combos send to same slot and is more generic than
          accessing via "ui->combobox1->xxxx "

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            yc2986
            wrote on last edited by yc2986
            #5

            @mrjj @jsulm

            I have figured out my problem. I have a customed PlotCurve class which is inherited from QwtPlotCurve class in the Qwt library. The parent class is not a QObject at all... which I mistakenly believed should be a QObject class from the very start. My problem is like no matter how I call the QObject::sender() method the compiler keeps throwing method not found error. Now I have the solution. Just to take an extra inheritance from the QObject and all problem solve with the solution from @jsulm

            class PlotCurve : public QwtPlotCurve, public QObject {
                Q_OBJECT
                //...
            }
            

            Thank you very much for the suggestion!

            Best regards,
            yc2986

            update:
            The above double inheritance way cannot solve the problem since QwtPlotCurve should not be inherited from QObject. What I do is write a wrapper class inherited from QWidget and store the PlotCurve pointers in a private vector. Then all problem cleared. Cheer.

            1 Reply Last reply
            1

            • Login

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