Can not cast into the derived class from QScrollBar
I defined a class ViewScrollBar derived from QScrollBar. There is also a public slot: void currentValue(i nt value); I hope to use this slot in another class.
Code:
#include <QScrollBar>
{
Q_OBJECT
public:
ViewScrollBar();
~ViewScrollBar();
int getCurrentValue();
public slots:
void currentValue(i nt value);
private:
int currentPos;
};
Then I get the scroll bar from the QGraphicsView by the method:
ViewScrollBar *hScrollBar=static_cast<ViewScrollBar*>(graphicsVi ew->horizontalScrollBar());
I connect the signal valueChanged() from QScrollBar with my public slot currentValue(i nt value) in ViewScrollBar class.
connect(hScrollBar, SIGNAL(valueChanged(int)),hScrollBar, SLOT(currentValue(int)));
when I run, there is always warning that:
Object::connect: No such slot QScrollBar::currentValue(int).
The object hScrollBar is ViewScrollBar now. But it is still regarded as its parent class. How can cast it from QScrollBar to ViewScrollBar?
Re: Can not cast into the derived class from QScrollBar
Do you have the Q_OBJECT macro and is the above code a spelling error with the space between "i" and "nt"? If you added Q_OBJECT later, did you remember to run qmake afterwards?
Re: Can not cast into the derived class from QScrollBar
Yes, I have Q_OBJECT used in header file.
Sorry, actually, there is on misspelling in my code. Maybe when I wrote this post, I made a mistake.
void currentValue(int value)