I am new to Qt and am having trouble getting the connect-SIGNAL-SLOT mechanism working. When I try to use the valueChanged signal with a QSlider subclass I get the error "No such signal SimpleSlider::valueChanged" on connect. If I try to do similar code with the sliderReleased signal connect returns true but the trace has the error message "QMetaObject::indexOfSignal: signal sliderReleased() from QSlider redefined in SimpleSlider" and my SLOT function never gets called. Below is my code. Please help.
#ifndef SIMPLESLIDER_H
#define SIMPLESLIDER_H
#include <QtGui>
#include "ui_simpleslider.h"
class SimpleSlider
: public QSlider{
Q_OBJECT
public:
SimpleSlider
(Qt
::Orientation orientation,
QWidget *parent
= 0);
~SimpleSlider();
signals:
void valueChanged(int value);
void sliderReleased();
private slots:
void valueHasChanged();
private:
};
#endif // SIMPLESLIDER_H
#ifndef SIMPLESLIDER_H
#define SIMPLESLIDER_H
#include <QtGui>
#include "ui_simpleslider.h"
class SimpleSlider : public QSlider
{
Q_OBJECT
public:
SimpleSlider(Qt::Orientation orientation, QWidget *parent = 0);
~SimpleSlider();
signals:
void valueChanged(int value);
void sliderReleased();
private slots:
void valueHasChanged();
private:
};
#endif // SIMPLESLIDER_H
To copy to clipboard, switch view to plain text mode
#include "simpleslider.h"
SimpleSlider
::SimpleSlider(Qt
::Orientation orientation,
QWidget *parent
){
bool retval = connect(this, SIGNAL(valueChanged(int value)), this, SLOT(valueHasChanged()));
retval = connect(this, SIGNAL(sliderReleased()), this, SLOT(valueHasChanged()));
}
SimpleSlider::~SimpleSlider()
{
}
void SimpleSlider::valueHasChanged()
{
QMessageBox::information(this,
"SimpleSlider",
"Value has Changed");
}
#include "simpleslider.h"
SimpleSlider::SimpleSlider(Qt::Orientation orientation, QWidget *parent)
: QSlider(orientation, parent)
{
bool retval = connect(this, SIGNAL(valueChanged(int value)), this, SLOT(valueHasChanged()));
retval = connect(this, SIGNAL(sliderReleased()), this, SLOT(valueHasChanged()));
}
SimpleSlider::~SimpleSlider()
{
}
void SimpleSlider::valueHasChanged()
{
QMessageBox::information(this, "SimpleSlider", "Value has Changed");
}
To copy to clipboard, switch view to plain text mode
Bookmarks