Results 1 to 3 of 3

Thread: Strange compiler behaviour (compiler passes wrong argument)

  1. #1
    Join Date
    Nov 2010
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Strange compiler behaviour (compiler passes wrong argument)

    I have following class declaration:
    Qt Code:
    1. class GraphicsArc : public GraphicsComponent
    2. {
    3. public:
    4. enum { Type = Arc };
    5.  
    6. explicit GraphicsArc();
    7. explicit GraphicsArc(const ArcF &arc);
    8. explicit GraphicsArc(qreal cx, qreal cy, qreal radius, qreal startAngle, qreal spanAngle);
    9. ~GraphicsArc();
    10.  
    11. QRectF boundingRect() const;
    12. QPainterPath shape() const;
    13. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    14.  
    15. ArcF arc() const;
    16. void setArc(const ArcF &arc);
    17.  
    18. int type() const { return Type; }
    19.  
    20. private:
    21. void updateBoundingRect();
    22. QPointF endPoint(const QPointF &center, qreal radius, qreal angle);
    23.  
    24. ArcF m_arc;
    25. QRectF bounding_rect;
    26. };
    To copy to clipboard, switch view to plain text mode 

    and problem is here:

    Qt Code:
    1. ...
    2. QPainterPath GraphicsArc::shape() const
    3. {
    4.  
    5. QPointF sp1 (endPoint(m_arc.center(), m_arc.radius() - 5, -m_arc.startAngle()));
    6. QPointF sp2 (endPoint(m_arc.center(), m_arc.radius() + 5, -m_arc.startAngle()));
    7. ...
    To copy to clipboard, switch view to plain text mode 

    Compiler says:
    ..\TestGraphicView\graphicsarc.cpp: In member function 'virtual QPainterPath GraphicsArc::shape() const':
    ..\TestGraphicView\graphicsarc.cpp:42: error: passing 'const GraphicsArc' as 'this' argument of 'QPointF GraphicsArc::endPoint(const QPointF&, qreal, qreal)' discards qualifiers
    ..\TestGraphicView\graphicsarc.cpp:43: error: passing 'const GraphicsArc' as 'this' argument of 'QPointF GraphicsArc::endPoint(const QPointF&, qreal, qreal)' discards qualifiers
    I do not understand that, because there also a function updateBoundingRect, which also use endPoint(), and does not have same problem. I think it has something to do with virtual function, but I am not sure what.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Strange compiler behaviour (compiler passes wrong argument)

    It means you try to change a member of the class within a const function.

    Calling the endPoint functions changes the state of the class.

  3. The following user says thank you to tbscope for this useful post:

    SasaVilic (2nd November 2010)

  4. #3
    Join Date
    Nov 2010
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Strange compiler behaviour (compiler passes wrong argument)

    Quote Originally Posted by tbscope View Post
    It means you try to change a member of the class within a const function.

    Calling the endPoint functions changes the state of the class.
    Wow, how could I forget that. Thank you very much.

Similar Threads

  1. Compiler
    By CHeader in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2008, 16:45
  2. Intel C++ compiler w/ Qt?
    By gfunk in forum Qt Programming
    Replies: 1
    Last Post: 23rd August 2007, 23:11
  3. default argument compiler warning
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2007, 15:57
  4. Alternative Compiler
    By Rayven in forum Newbie
    Replies: 3
    Last Post: 25th May 2006, 21:57
  5. Qt or Compiler bug?
    By jrideout in forum Qt Programming
    Replies: 5
    Last Post: 2nd March 2006, 22:34

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.