Results 1 to 9 of 9

Thread: not showing DotLine in a for loop setting Samples with Qvector

  1. #1
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default not showing DotLine in a for loop setting Samples with Qvector

    Hi,

    when I use a ForLoop for initialing a QVector<double>, and have a setPen like this:
    Qt Code:
    1. curve.setPen(Qt::red, 4, Qt::DotLine)
    To copy to clipboard, switch view to plain text mode 
    , the plot can not show the DotLine style. code is:


    Qt Code:
    1. QVector<double> t(20);
    2. //t<<1<<2<<3<<4<<5<<6<<7<<8<<9; //if I replace this line with under ForLoop the problem is solved.
    3. for(int i=0;i<10;i++)
    4. {
    5. t[i]=i;
    6. }
    7. curve.setSamples(t,t );
    8. curve.setPen(Qt::red, 4, Qt::DotLine);
    9. curve.attach(&plot);
    10.  
    11. plot.show();
    To copy to clipboard, switch view to plain text mode 

    I uploaded a picture of this. Thanks for any help
    NotShowStyle.png

  2. #2
    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: not showing DotLine in a for loop setting Samples with Qvector

    You have a vector of 20 points, where the upper 10 points stay at the default value ( 0, 0 ). So your curve goes up and down - guess with the effect, that the dots of the down path fills the gaps of the up path somehow.

    Uwe

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

    Alex22 (10th December 2015)

  4. #3
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: not showing DotLine in a for loop setting Samples with Qvector

    @Uwe thanks!!! I have asked a question here. My data is stored in an array like double data[1000][100]. What is your idea about using setRawSamples instaed of setSamples to plot two selected columns of the data together. for example:
    Qt Code:
    1. for(int i=0;i<1000;i++)
    2. {
    3. for(int j=0;j<100;j++)
    4. {
    5. data[i][j]=(i+1)*(j+1);
    6. }
    7. }
    8. _curve[0]->setRawSamples(data[0],data[1],1000);//your idea using this instead of setSamples???
    To copy to clipboard, switch view to plain text mode 


    So many thanks for any help.
    Last edited by Alex22; 10th December 2015 at 13:25.

  5. #4
    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: not showing DotLine in a for loop setting Samples with Qvector

    Use QVector, it's easier and because of its copy on write semantics you also don't have any copying.

    Uwe

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

    Alex22 (10th December 2015)

  7. #5
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: not showing DotLine in a for loop setting Samples with Qvector

    @Uwe thanks so much. do you mean it is better to use this: setSamples (const QVector< double > &xData, const QVector< double > &yData)?

    then I need to have a QVector in 2 Dimensional (2D). could you help me to convert "double data[1000][100]" to a 2D QVector?
    So so many thanks for your help Uwe!!!

  8. #6
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: not showing DotLine in a for loop setting Samples with Qvector

    Quote Originally Posted by Uwe View Post
    You have a vector of 20 points, where the upper 10 points stay at the default value ( 0, 0 ). So your curve goes up and down - guess with the effect, that the dots of the down path fills the gaps of the up path somehow.
    Uwe
    Uwe, can it be prevented to go down and make it only go up ?

  9. #7
    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: not showing DotLine in a for loop setting Samples with Qvector

    Sure fix your code.

    Uwe

  10. #8
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: not showing DotLine in a for loop setting Samples with Qvector

    Quote Originally Posted by Uwe View Post
    Sure fix your code.

    Uwe
    Uwe, by making (i<20) in ForLoop it is ok, but somewhere I need it's be till 10 (i<10). how "curve.setSamples(t,t )" can be set till 10 and not till 20?

    I repeat above code again:

    Qt Code:
    1. QVector<double> t(20); //I need this size to be always 20.
    2. for(int i=0;i<10;i++)//I need somewhere "i" goes to 10 not to 20
    3. {
    4. t[i]=i;
    5. }
    6. curve.setSamples(t,t );
    7. curve.setPen(Qt::red, 4, Qt::DotLine);
    8. curve.attach(&plot);
    9.  
    10. plot.show();
    To copy to clipboard, switch view to plain text mode 

    one way is to resize t by t.resize(10). is there any other idea?

    Uwe, thanks so much for your patient. my another question is:
    Advantages of setRawSamples to setSamples is: in setRawSamples there is no copy and it uses the passing addresses of "x" and "y" but in setSamples there is a deep copy (even we can delete and free memory after deep copy). am I right?
    thanks a lot for more help

  11. #9
    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: not showing DotLine in a for loop setting Samples with Qvector

    Quote Originally Posted by Alex22 View Post
    Advantages of setRawSamples to setSamples is: in setRawSamples there is no copy and it uses the passing addresses of "x" and "y" but in setSamples there is a deep copy (even we can delete and free memory after deep copy). am I right?
    No QVector ( like all Qt containers ) is implicitly shared. But I'm not going to explain this any further - Qt documentation does it better than I could do.

    Uwe

    PS: this forum is related to Qwt, please use the Newbie section, when having Qt/C++ beginner questions

Similar Threads

  1. Replies: 5
    Last Post: 3rd September 2011, 00:11
  2. Replies: 1
    Last Post: 14th February 2011, 05:30
  3. Can't build samples
    By kalons in forum Installation and Deployment
    Replies: 5
    Last Post: 22nd December 2010, 20:06
  4. BuddyList - samples
    By underlife in forum Newbie
    Replies: 1
    Last Post: 7th October 2009, 14:09
  5. How do you build QT without the samples??
    By Joachie in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2009, 22:16

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.