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. ValueChanged signal not being emitted in subclass
Forum Updated to NodeBB v4.3 + New Features

ValueChanged signal not being emitted in subclass

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 5.3k 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.
  • D Offline
    D Offline
    dnadave
    wrote on last edited by
    #1

    I have created a subclass of QDoubleSpinBox such that it stores a double unadulturated side-by-side a setDecimaled double using the native value for QDoubleSpinBox. The setValue slot is receiving a signal from connected widgets, but the valueChanged signal is not emitting a signal.

    For example, I have a custom double slider (that was working fine with a QDoubleSpinBox) connected to my subclassed QDoubleSpinBox. If I move the slider, the value in the spinbox updates. If I change the spinbox value, the slider does not respond. Same thing if I connect two of my subclassed spinboxes together.

    I know the code is a bit hackish, so I would grateful for any suggestions for improvement.

    Thanks!

    Dave H

    qdpinbox.h:

    @
    #ifndef QDSPINBOX_H
    #define QDSPINBOX_H

    #include <QDoubleSpinBox>

    class QDSpinBox : public QDoubleSpinBox
    {
    Q_OBJECT
    public:
    explicit QDSpinBox();
    explicit QDSpinBox( QWidget * );
    double getRValue() { return rvalue; }
    void setPrecision( int i ) { precision = i; }
    protected:
    double valueFromText( const QString &text ) const;
    QString textFromValue( double value ) const;
    QSize sizeHint() const
    {
    return cachedSizeHint;
    }
    signals:
    void valueChanged( double );
    void valueChanged( QString & );
    public slots:
    void setValue( double );
    void setDecimals( int );
    private:
    int precision;
    double rvalue;
    QSize cachedSizeHint;
    };

    #endif
    @

    qdspinbox.cpp

    @
    #include "qdspinbox.h"

    QDSpinBox::QDSpinBox():QDoubleSpinBox()
    {
    precision = 4;
    cachedSizeHint = QDoubleSpinBox::sizeHint();
    }

    QDSpinBox::QDSpinBox( QWidget *parent = 0 ):QDoubleSpinBox( parent )
    {
    precision = 4;
    cachedSizeHint = QDoubleSpinBox::sizeHint();
    }

    QString QDSpinBox::textFromValue( double value ) const
    {
    return QString::number( value , 'f' , precision );
    }

    double QDSpinBox::valueFromText( const QString &text ) const
    {
    bool ok;
    return text.toDouble( &ok );
    }

    void QDSpinBox::setDecimals( int decimals )
    {
    setValue( rvalue );
    QDoubleSpinBox::setDecimals( decimals );
    emit valueChanged( rvalue );
    }

    void QDSpinBox::setValue( double val )
    {
    if ( rvalue != val )
    {
    rvalue = val;
    QDoubleSpinBox::setValue( val );
    emit valueChanged( value() );
    }
    }
    @

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      My first guess would be that the connect statement does not use your derived class.
      You should post also the connect statement of your signal to whatever slot you are using.

      Vote the answer(s) that helped you to solve your issue(s)

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

        When you define own valueChanged( QString & );
        you shadow original QSpinBox::void valueChanged( QString & );
        That's why your slots are not invoked.

        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