You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, February 21st 2012, 9:43pm

add my own slot to QSlider

hi,
i trying to make my own app. there is horizontal slider and 2 buttons to decrement and increment slider's value.
so i would like to add my own slot to QSlider, so i make subclass like this:

myqslider.h:

Source code

1
2
3
4
5
6
7
8
9
10
#include <QSlider>
class MyQSlider : public QSlider
{
    Q_OBJECT
public:
    explicit MyQSlider(QSlider *parent = 0);    
public slots:
    void valueInc();
    void valueDec();
};

myqslider.cpp:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
#include "myqslider.h"

MyQSlider::MyQSlider(QSlider *parent) : 
    QSlider(parent)
{
}
void MyQSlider::valueDec() {
    this->setValue(this->value()-1 );
}
void MyQSlider::valueInc() {
    this->setValue(this->value()+1);
}


everything is ok, but, when in Designer i right clicked on my slider and set Promote to.. and choose MyQSlider i get error from compiller: invalid conversion from 'Qwidget*' to 'QSlider*'

i use QtCreator 2.4.1 based on Qt 4.7.4

i am new in Qt and C++ too, so thanks very much for any advise how to fix it

This post has been edited 1 times, last edit by "keresan" (Feb 21st 2012, 9:51pm)