Results 1 to 4 of 4

Thread: An error in QwtScaleDiv::invert

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

    Default An error in QwtScaleDiv::invert

    Hello,

    I noticed an error in QwtScaleDiv::invert() (VS /analyze caught it) :

    Qt Code:
    1. for ( int i = 0; i < NTickTypes; i++ )
    2. {
    3. QList<double>& ticks = d_ticks[i];
    4.  
    5. const int size = ticks.count();
    6. const int size2 = size / 2;
    7.  
    8. for ( int i = 0; i < size2; i++ )
    9. qSwap( ticks[i], ticks[size - 1 - i] );
    10. }
    To copy to clipboard, switch view to plain text mode 

    I believe the second for() should use j or something instead of i.

    Thanks!

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: An error in QwtScaleDiv::invert

    It's not a bug (assuming that the inner loop really should use a new loop variable). The inner for loop uses a new instance of variable i. Check the output of the following small program:
    Qt Code:
    1. #include <iostream>
    2. using namespace std;
    3.  
    4. int main(int , char**)
    5. {
    6. for (int i=0; i < 5; i++)
    7. {
    8. cout << i << " ";
    9. for(int i=0; i < 3; i++)
    10. if(i == 0)
    11. cout << i << endl;
    12. else
    13. cout << " " << i << endl;
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    But I would also prefer a new name for the inner for loop variable just for code readability.

  3. #3
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: An error in QwtScaleDiv::invert

    Yes, you're right, I missed that.
    Too much late-night debugging with suspicious tools, I guess...

  4. #4
    Join Date
    Mar 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: An error in QwtScaleDiv::invert

    Uwe,

    Regarding your commit; just pointing out that you don't increment the j variable in the inner loop:

    for ( int j = 0; j < size2; i++ )
    qSwap( ticks[j], ticks[size - 1 - j] );

Similar Threads

  1. Replies: 1
    Last Post: 20th April 2011, 16:23
  2. PyQT QwtScaleDiv adds ticks to axis
    By mbernasocchi in forum Qwt
    Replies: 12
    Last Post: 13th April 2011, 11:29
  3. the invert of a QTransform's transposed
    By calmspeaker in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2011, 03:19
  4. is it posible to invert the axes?
    By jbca in forum Qwt
    Replies: 2
    Last Post: 18th January 2010, 15:34
  5. QwtPlotMagnifier Invert Wheel Zoom
    By jmsbc in forum Qwt
    Replies: 2
    Last Post: 12th March 2009, 23:12

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.