1 Attachment(s)
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:
Code:
curve.setPen(Qt::red, 4, Qt::DotLine)
, the plot can not show the DotLine style. code is:
Code:
QVector<double> t(20);
//t<<1<<2<<3<<4<<5<<6<<7<<8<<9; //if I replace this line with under ForLoop the problem is solved.
for(int i=0;i<10;i++)
{
t[i]=i;
}
curve.setSamples(t,t );
curve.setPen(Qt::red, 4, Qt::DotLine);
curve.attach(&plot);
plot.show();
I uploaded a picture of this. Thanks for any help
Attachment 11568
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
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:
Code:
for(int i=0;i<1000;i++)
{
for(int j=0;j<100;j++)
{
data[i][j]=(i+1)*(j+1);
}
}
_curve[0]->setRawSamples(data[0],data[1],1000);//your idea using this instead of setSamples???
So many thanks for any help.
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
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!!!
Re: not showing DotLine in a for loop setting Samples with Qvector
Quote:
Originally Posted by
Uwe
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 ?
Re: not showing DotLine in a for loop setting Samples with Qvector
Re: not showing DotLine in a for loop setting Samples with Qvector
Quote:
Originally Posted by
Uwe
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:
Code:
QVector<double> t(20); //I need this size to be always 20.
for(int i=0;i<10;i++)//I need somewhere "i" goes to 10 not to 20
{
t[i]=i;
}
curve.setSamples(t,t );
curve.setPen(Qt::red, 4, Qt::DotLine);
curve.attach(&plot);
plot.show();
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
Re: not showing DotLine in a for loop setting Samples with Qvector
Quote:
Originally Posted by
Alex22
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