Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Custom Slots

Why doesn't the slot Reset() work? I want the button "reset" to reset the value of the sider to zero.

class MySlider : public QSlider
{
   public:
    MySlider(Qt::Orientation orientation, QWidget *parent = 0) : QSlider(orientation parent){}

   public slots:
   void Reset()
   {
   this->setValue(0);
   }
};

//it doesnt work when i try this

MySlider * Slider = new MySlider(Qt::Horizontal, this);

QPushButton *Reset = new QPushButton(tr("Reset"), this);

connect(Reset, SIGNAL(clicked()), Slider, SLOT(Reset()) );
like image 516
Geore Shg Avatar asked Nov 26 '25 13:11

Geore Shg


1 Answers

Try adding Q_OBJECT to the private section of the class. This will cause moc to create the meta-data necessary for signals and slots to work. See http://doc.qt.io/archives/qt-4.7/qobject.html#Q_OBJECT

like image 152
Evan Teran Avatar answered Nov 29 '25 03:11

Evan Teran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!