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.
Qt Code:
#include <QScrollBar> { Q_OBJECT public: ViewScrollBar(); ~ViewScrollBar(); int getCurrentValue(); public slots: void currentValue(i nt value); private: int currentPos; };To copy to clipboard, switch view to plain text mode
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?
Bookmarks