Results 1 to 3 of 3

Thread: Can not cast into the derived class from QScrollBar

  1. #1
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default 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.
    Qt Code:
    1. #include <QScrollBar>
    2. class ViewScrollBar: public QScrollBar
    3. {
    4. Q_OBJECT
    5. public:
    6. ViewScrollBar();
    7. ~ViewScrollBar();
    8. int getCurrentValue();
    9.  
    10. public slots:
    11. void currentValue(i nt value);
    12.  
    13. private:
    14. int currentPos;
    15. };
    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?
    Last edited by wysota; 19th December 2008 at 08:20. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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?

  3. #3
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default 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)

Similar Threads

  1. no frame on Qlabel derived class
    By tupu_83 in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2008, 16:01
  2. Use QWidget derived class in Dialog
    By qtneuling in forum Qt Tools
    Replies: 2
    Last Post: 17th May 2008, 23:29
  3. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  4. Replies: 2
    Last Post: 20th September 2007, 12:27
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 07:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.