Results 1 to 3 of 3

Thread: passing 'const QwtSymbol' as 'this' argument of ... discard qualifiers

  1. #1
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default passing 'const QwtSymbol' as 'this' argument of ... discard qualifiers

    Hi,

    i subclassed QwtPlotCurve to add new functions that we need.
    One point is adding QwtPlotMarker into plot that belong to the curve and
    will be attached, detached, setVisible together with the curve. Is all working.

    But if some one change the color of the curve, all QwtPlotMarker should change
    the color also. The marker has a custom symbol and if i try to set the brush color
    o got this error:

    passing 'const QwtSymbol' as 'this' argument of void::QwtSymbol::setBrush(const QBrush&) discards qualifiers

    What i'm doing wrong?

    Qt Code:
    1. curve->setPen(color,2.0); // change curve color
    2. curve->setMarkerColor( color ) // change marker color
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // in class PlotCurve::PrivateData
    2. QList<QwtPlotMarker *> qlMarkerError1;
    3.  
    4.  
    5. void PlotCurve::setMarkerColor( QColor color ) const
    6. {
    7. foreach (QwtPlotMarker *marker, d_data->qlMarkerError1)
    8. {
    9. QBrush brush = marker->symbol()->brush();
    10. brush.setColor( color );
    11. marker->symbol()->setBrush( brush ); // ERROR LINE
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: passing 'const QwtSymbol' as 'this' argument of ... discard qualifiers

    I guess it is not possible to change the color af a symbol once attached to plot.
    This can my seen in examples/sinusplot. There an ArrawSymbol was attached to plot
    pointing to a curve. We add other symbols to our plot in the same way, but they
    are using the color of the curve. The user is allowed to change the color of the curve
    and the symbols chould change the color in the same way, which is not possible by
    original Qwt code, it is const ?

    The only workaround was to detach the old symbols from plot, generate new symbols
    that are added as QwtPlotMarker (like in example) with the new color of the curve.
    The old objects are still in memory, not deleteable dynamically and unused.
    They are deleted later by QwtPlotDict when the deconstructor of plot is called.
    That is a memory leak of Qwt.

    Plz tell me, if i'm wrong.

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: passing 'const QwtSymbol' as 'this' argument of ... discard qualifiers

    The reason for being const is, that changing attributes of a symbol behind the back of the plot item doesn't trigger an auto-replot.
    But of course you can simply cast the constness away, set the color and do the missing replot manually.

    The "auto-replot aware" way to change the symbol of a marker would be to assign a new symbol with QwtPlotMarker::setSymbol(). This call deletes the old symbol - not sure, where you see a memory leak.

    Uwe

Similar Threads

  1. Replies: 0
    Last Post: 22nd June 2013, 11:02
  2. Tooltip to QwtSymbol ???
    By jesse_mark in forum Qwt
    Replies: 15
    Last Post: 17th October 2012, 10:49
  3. Replies: 2
    Last Post: 11th August 2011, 16:42
  4. Replies: 4
    Last Post: 20th August 2010, 14:54
  5. const member and const method
    By mickey in forum General Programming
    Replies: 8
    Last Post: 9th April 2008, 10:44

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.