Results 1 to 3 of 3

Thread: A patch to fix some compiler warnings in qwt

  1. #1
    Join Date
    Sep 2010
    Posts
    43
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default A patch to fix some compiler warnings in qwt

    Hello,

    I'm posting this here because my emails to qwt-interest don't seem to be getting through (they're not shown in sourceforge archives).

    We're building a partial version of Qwt6 (SVN version) as part of our project build (generating qwt shared library).

    Here are the gcc flags we're using:
    -Wall -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wpointer-arith -Wsign-compare -Wsign-promo -Wundef -Wwrite-strings

    I'm attaching a patch (against current SVN) that fixes some of the warnings. The majority of them is about casting away const qualifiers. There's also one about QwtPlotZoomer::move() hiding QwtPlotPicker::move() and one uncertain choice of overload in QDebug operator<<( QDebug debug, const QwtScaleMap &map ).

    Note that while this is the majority of warnings we get, it's not all of them. I may be able to do another full sweep later (and send another patch).

    The patch: qwt_fix_warnings.diff

    Cheers and thanks for the great library,
    Alexander

    P.S. These are the warnings I fixed:
    Qt Code:
    1. qwt_dyngrid_layout.cpp: In member function ‘int QwtDynGridLayout::maxRowWidth(int) const’:
    2. qwt_dyngrid_layout.cpp:288:32: warning: cast from type ‘const QwtDynGridLayout* const’ to type ‘QwtDynGridLayout*’ casts away qualifiers
    3. qwt_dyngrid_layout.cpp: In member function ‘virtual int QwtDynGridLayout::maxItemWidth() const’:
    4. qwt_dyngrid_layout.cpp:314:32: warning: cast from type ‘const QwtDynGridLayout* const’ to type ‘QwtDynGridLayout*’ casts away qualifiers
    5. qwt_dyngrid_layout.cpp: In member function ‘QList<QRect> QwtDynGridLayout::layoutItems(const QRect&, uint) const’:
    6. qwt_dyngrid_layout.cpp:359:52: warning: cast from type ‘const QwtDynGridLayout* const’ to type ‘QwtDynGridLayout*’ casts away qualifiers
    7. qwt_dyngrid_layout.cpp: In member function ‘void QwtDynGridLayout::layoutGrid(uint, QVector<int>&, QVector<int>&) const’:
    8. qwt_dyngrid_layout.cpp:412:32: warning: cast from type ‘const QwtDynGridLayout* const’ to type ‘QwtDynGridLayout*’ casts away qualifiers
    9. qwt_legend.cpp: In member function ‘const QWidget* QwtLegend::PrivateData::LegendMap::find(const QwtLegendItemManager*) const’:
    10. qwt_legend.cpp:158:57: warning: cast from type ‘const QwtLegendItemManager*’ to type ‘QwtLegendItemManager*’ casts away qualifiers
    11. qwt_legend.cpp:161:48: warning: cast from type ‘const QwtLegendItemManager*’ to type ‘QwtLegendItemManager*’ casts away qualifiers
    12. qwt_legend.cpp: In member function ‘QWidget* QwtLegend::PrivateData::LegendMap::find(const QwtLegendItemManager*)’:
    13. qwt_legend.cpp:166:57: warning: cast from type ‘const QwtLegendItemManager*’ to type ‘QwtLegendItemManager*’ casts away qualifiers
    14. qwt_legend.cpp:169:48: warning: cast from type ‘const QwtLegendItemManager*’ to type ‘QwtLegendItemManager*’ casts away qualifiers
    15. qwt_legend.cpp: In member function ‘const QwtLegendItemManager* QwtLegend::PrivateData::LegendMap::find(const QWidget*) const’:
    16. qwt_legend.cpp:175:46: warning: cast from type ‘const QWidget*’ to type ‘QWidget*’ casts away qualifiers
    17. qwt_legend.cpp:178:37: warning: cast from type ‘const QWidget*’ to type ‘QWidget*’ casts away qualifiers
    18. qwt_legend.cpp: In member function ‘QwtLegendItemManager* QwtLegend::PrivateData::LegendMap::find(const QWidget*)’:
    19. qwt_legend.cpp:184:46: warning: cast from type ‘const QWidget*’ to type ‘QWidget*’ casts away qualifiers
    20. qwt_legend.cpp:187:63: warning: cast from type ‘const QWidget*’ to type ‘QWidget*’ casts away qualifiers
    21. qwt_legend.cpp:187:69: warning: cast from type ‘const QwtLegendItemManager*’ to type ‘QwtLegendItemManager*’ casts away qualifiers
    22. qwt_picker.cpp: In member function ‘virtual void QwtPicker::transition(const QEvent*)’:
    23. qwt_picker.cpp:1046:54: warning: cast from type ‘const QMouseEvent*’ to type ‘QMouseEvent*’ casts away qualifiers
    24. qwt_picker.cpp: In member function ‘virtual QRect QwtPicker::pickRect() const’:
    25. qwt_picker.cpp:1343:30: warning: cast from type ‘const QFrame*’ to type ‘QFrame*’ casts away qualifiers
    26. qwt_plot_canvas.cpp: In member function ‘const QwtPlot* QwtPlotCanvas::plot() const’:
    27. qwt_plot_canvas.cpp:81:29: warning: cast from type ‘const QwtPlot*’ to type ‘QwtPlot*’ casts away qualifiers
    28. qwt_plot_magnifier.cpp: In member function ‘const QwtPlotCanvas* QwtPlotMagnifier::canvas() const’:
    29. qwt_plot_magnifier.cpp:90:36: warning: cast from type ‘const QwtPlotMagnifier* const’ to type ‘QwtPlotMagnifier*’ casts away qualifiers
    30. qwt_plot_magnifier.cpp: In member function ‘const QwtPlot* QwtPlotMagnifier::plot() const’:
    31. qwt_plot_magnifier.cpp:110:36: warning: cast from type ‘const QwtPlotMagnifier* const’ to type ‘QwtPlotMagnifier*’ casts away qualifiers
    32. qwt_plot_panner.cpp: In member function ‘const QwtPlotCanvas* QwtPlotPanner::canvas() const’:
    33. qwt_plot_panner.cpp:97:33: warning: cast from type ‘const QwtPlotPanner* const’ to type ‘QwtPlotPanner*’ casts away qualifiers
    34. qwt_plot_panner.cpp: In member function ‘const QwtPlot* QwtPlotPanner::plot() const’:
    35. qwt_plot_panner.cpp:117:33: warning: cast from type ‘const QwtPlotPanner* const’ to type ‘QwtPlotPanner*’ casts away qualifiers
    36. qwt_plot_picker.cpp: In member function ‘const QwtPlotCanvas* QwtPlotPicker::canvas() const’:
    37. qwt_plot_picker.cpp:116:33: warning: cast from type ‘const QwtPlotPicker* const’ to type ‘QwtPlotPicker*’ casts away qualifiers
    38. qwt_plot_picker.cpp: In member function ‘const QwtPlot* QwtPlotPicker::plot() const’:
    39. qwt_plot_picker.cpp:136:33: warning: cast from type ‘const QwtPlotPicker* const’ to type ‘QwtPlotPicker*’ casts away qualifiers
    40. qwt_plot_renderer.cpp: In member function ‘virtual void QwtPlotRenderer::renderLegendItem(const QwtPlot*, QPainter*, const QWidget*, const QRectF&) const’:
    41. qwt_plot_renderer.cpp:540:50: warning: cast from type ‘const QwtLegendItem*’ to type ‘QwtLegendItem*’ casts away qualifiers
    42. qwt_plot_renderer.cpp: In member function ‘virtual void QwtPlotRenderer::renderScale(const QwtPlot*, QPainter*, int, int, int, int, const QRectF&) const’:
    43. qwt_plot_renderer.cpp:644:65: warning: cast from type ‘const QwtScaleDraw*’ to type ‘QwtScaleDraw*’ casts away qualifiers
    44. qwt_plot_rescaler.cpp: In member function ‘const QwtPlotCanvas* QwtPlotRescaler::canvas() const’:
    45. qwt_plot_rescaler.cpp:282:35: warning: cast from type ‘const QwtPlotRescaler* const’ to type ‘QwtPlotRescaler*’ casts away qualifiers
    46. qwt_plot_rescaler.cpp: In member function ‘const QwtPlot* QwtPlotRescaler::plot() const’:
    47. qwt_plot_rescaler.cpp:302:35: warning: cast from type ‘const QwtPlotRescaler* const’ to type ‘QwtPlotRescaler*’ casts away qualifiers
    48. qwt_plot_rescaler.cpp: In member function ‘virtual void QwtPlotRescaler::updateScales(QwtInterval*) const’:
    49. qwt_plot_rescaler.cpp:578:38: warning: cast from type ‘const QwtPlot*’ to type ‘QwtPlot*’ casts away qualifiers
    50. qwt_plot_scaleitem.cpp: In member function ‘virtual void QwtPlotScaleItem::draw(QPainter*, const QwtScaleMap&, const QwtScaleMap&, const QRectF&) const’:
    51. qwt_plot_scaleitem.cpp:330:59: warning: cast from type ‘const QwtPlotScaleItem* const’ to type ‘QwtPlotScaleItem*’ casts away qualifiers
    52. In file included from qwt_plot_zoomer.cpp:10:0:
    53. qwt_plot_picker.h:104:18: warning: ‘virtual void QwtPlotPicker::move(const QPoint&)’ was hidden
    54. qwt_plot_zoomer.h:70:18: warning: by ‘virtual void QwtPlotZoomer::move(double, double)’
    55. qwt_raster_data.cpp: In member function ‘virtual QwtRasterData::ContourLines QwtRasterData::contourLines(const QRectF&, const QSize&, const QList<double>&, int) const’:
    56. qwt_raster_data.cpp:270:25: warning: cast from type ‘const QwtRasterData* const’ to type ‘QwtRasterData*’ casts away qualifiers
    57. qwt_raster_data.cpp:382:25: warning: cast from type ‘const QwtRasterData* const’ to type ‘QwtRasterData*’ casts away qualifiers
    58. qwt_scale_map.cpp: In function ‘QDebug operator<<(QDebug, const QwtScaleMap&)’:
    59. qwt_scale_map.cpp:287:39: warning: passing ‘QwtScaleTransformation::Type’ chooses ‘int’ over ‘unsigned int’
    60. qwt_scale_map.cpp:287:39: warning: in call to ‘QDebug& QDebug::operator<<(int)’
    61. qwt_text.cpp: In destructor ‘QwtTextEngineDict::~QwtTextEngineDict()’:
    62. qwt_text.cpp:67:67: warning: cast from type ‘const QwtTextEngine*’ to type ‘QwtTextEngine*’ casts away qualifiers
    63. qwt_text.cpp: In member function ‘const QwtTextEngine* QwtTextEngineDict::textEngine(const QString&, QwtText::TextFormat) const’:
    64. qwt_text.cpp:84:47: warning: cast from type ‘const QwtTextEngine*’ to type ‘QwtTextEngine*’ casts away qualifiers
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A patch to fix some compiler warnings in qwt

    Quote Originally Posted by alex_sh View Post
    warnings about C casts ...
    Well warnings about that casts are casting - even if the compiler offers to enable such warnings they doesn't make much sense to me. And enabling additional warning levels for compiling 3rd party libraries doesn't seem to be something that a user needs to do.

    Anyway, the reason for these warnings is because Qwt still uses C casts instead of C++ casts. This decsision was made because of compiler limitations 10 years ago. This should be pointless nowadays and Qt itself uses C++ casts.

    I will replace all C casts.

    There's also one about QwtPlotZoomer::move()
    This one is indeed worth a warning as the compiler can't identify the right move method from the parameter type, when one of them has been overloaded. I will change this.
    uncertain choice of overload in QDebug operator<<( QDebug debug, const QwtScaleMap &map )
    When you mean the missing enum to int cast - I will add it.

    Uwe

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

    alex_sh (18th November 2010)

  4. #3
    Join Date
    Sep 2010
    Posts
    43
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A patch to fix some compiler warnings in qwt

    Thanks, I hope the patch is helpful as well, you can see from it that I actually removed some of the casts because they were unnecessary (perhaps they were copy/paste leftovers).

Similar Threads

  1. Replies: 2
    Last Post: 22nd April 2012, 07:12
  2. Strange compiler behaviour (compiler passes wrong argument)
    By SasaVilic in forum General Programming
    Replies: 2
    Last Post: 2nd November 2010, 11:36
  3. Where are my compiler warnings?
    By drhex in forum General Programming
    Replies: 5
    Last Post: 18th February 2009, 21:28
  4. Crosscompiling warnings
    By SteM in forum Installation and Deployment
    Replies: 1
    Last Post: 2nd August 2007, 20:26

Tags for this Thread

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.