3

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()) );
4

1 に答える 1

6

Q_OBJECTクラスのプライベート セクションに追加してみてください。これによりmoc、シグナルとスロットが機能するために必要なメタデータが作成されます。http://doc.qt.io/archives/qt-4.7/qobject.html#Q_OBJECTを参照してください。

于 2011-10-29T04:17:16.143 に答える