Is that any problem in my this function?
Code:
// draw plotter line using QPainter function drawPolyline
void GenePlotter
::drawPlotterLine(QPainter *painter
) {
QRect rect
(Margin, Margin,
width() - 2 * Margin, height() - 2 * Margin);
if (!rect.isValid())
return;
painter->setClipRect(rect.adjusted(+1, +1, -1, -1));
//draw best lines
painter
->setPen
(QPen(Qt
::red,
1.0));
const QPointF* point
=bestPoints.
data();
//bestPoints is a vector painter->drawPolyline(point,bestPoints.size());
//draw average line
painter
->setPen
(QPen(Qt
::blue,
1.0));
//X is the same point=avgPoints.data(); //avgPoints is also a vector
painter->drawPolyline(point,avgPoints.size());
Is that any problem in the above code? That's something wrong, But I cann't tell. It fails to draw the average line.
Thanks
Re: Is that any problem in my this function?
I'm sure that the data in the vector is OK. but I can not draw line.
Re: Is that any problem in my this function?
can you show us code where you use this method?
Re: Is that any problem in my this function?
what is the size of avgPoints?
Re: Is that any problem in my this function?
Code:
void GenePlotter::refreshPixmap()
{
pixmap.fill(this, 0, 0);
painter.initFrom(this);
drawGrid(&painter); // This line works perfectly good
if(couter!=0)
drawPlotterLine(&painter); // here can't draw line
update();
}
Re: Is that any problem in my this function?
Quote:
Originally Posted by
talk2amulya
what is the size of avgPoints?
In fact, the size will increase when the app runs, for example the size will increase from 1 to 100. And I will call the function to redraw the pixmap for 100 times.
Re: Is that any problem in my this function?
stupid question, but maybe couter == 0? :)
Re: Is that any problem in my this function?
Code:
// perform one generaion evolution and update the points of the plotter
void GenePlotter::execOnce()
{
geneGroup.performEvolution();
point.setX(couter);
point.setY(((geneGroup.getGroup())+GeneGroup::popSize)->getfitness());
bestPoints.push_back(point);
point.setY(geneGroup.getAvg());
// x are the same of these two point.
avgPoints.push_back(point);
refreshPixmap();
}
void GenePlotter::oneStep()
{
++couter;
if(couter<generation)
{
execOnce();
}
}
void GenePlotter::runAll()
{
settingButton->setEnabled(false);
oneStepButton->setEnabled(false);
runAllButton->setEnabled(false);
qApp->processEvents();
if(couter==0)
++couter;
while(couter<generation)
{
++couter;
execOnce();
repaint();
}
settingButton->setEnabled(true);
oneStepButton->setEnabled(true);
runAllButton->setEnabled(true);
}
More code
Re: Is that any problem in my this function?
if you do this
Code:
void GenePlotter::refreshPixmap()
{
pixmap.fill(this, 0, 0);
painter.initFrom(this);
drawGrid(&painter); // This line works perfectly good
drawPlotterLine(&painter); // here can't draw line
update();
}
is something changed?
Re: Is that any problem in my this function?
Quote:
Originally Posted by
spirit
stupid question, but maybe couter == 0? :)
No, the couter will increase. I make it draw only couter >0 ;
Code:
// In the construtor function
connect(oneStepButton,SIGNAL(clicked()),this,SLOT(oneStep()));
connect(runAllButton,SIGNAL(clicked()),this,SLOT(runAll()));
Re: Is that any problem in my this function?
Re: Is that any problem in my this function?
Quote:
Originally Posted by
HelloDan
Code:
// draw plotter line using QPainter function drawPolyline
void GenePlotter
::drawPlotterLine(QPainter *painter
) {
QRect rect
(Margin, Margin,
width() - 2 * Margin, height() - 2 * Margin);
if (!rect.isValid())
return;
painter->setClipRect(rect.adjusted(+1, +1, -1, -1));
//draw best lines
painter
->setPen
(QPen(Qt
::red,
1.0));
const QPointF* point
=bestPoints.
data();
//bestPoints is a vector painter->drawPolyline(point,bestPoints.size());
//draw average line
painter
->setPen
(QPen(Qt
::blue,
1.0));
//X is the same point=avgPoints.data(); //avgPoints is also a vector
painter->drawPolyline(point,avgPoints.size());
Is that any problem in the above code? That's something wrong, But I cann't tell. It fails to draw the average line.
Thanks
I am sure that the points are in the rectangle
Re: Is that any problem in my this function?
if you comment all code in GenePlotter::drawPlotterLine and draw some other shape, circle for example, in this case is something changed?
Re: Is that any problem in my this function?
why dont you debug the whole issue..you'll get to the core of the whole problem and thus would be workin in the right direction, its really hard to point out anything like that..just random guesses
Re: Is that any problem in my this function?
Quote:
Originally Posted by
spirit
if you comment all code in GenePlotter::drawPlotterLine and draw some other shape, circle for example, in this case is something changed?
Code:
painter->drawLine(line);
// I draw a line to test, but the line didn't turn up too.
Re: Is that any problem in my this function?
Quote:
Originally Posted by
talk2amulya
why dont you debug the whole issue..you'll get to the core of the whole problem and thus would be workin in the right direction, its really hard to point out anything like that..just random guesses
Thanks! But in fact I don't know how to debug a progam in a console. For My major is not computer relative, I cann't get help from classmates around me. I just have interest in C++. I debug my app only use a QmessageBox to popup to show some info. I don't know how to use gdb and how to debug. Can you give me some URL about how to debug it ? thanks again!
Re: Is that any problem in my this function?
try to cahnge coloro of line in code above, for example use Qt::red.
or if you have possibility to attach all you code then it would be nice. :)
Re: Is that any problem in my this function?
Quote:
Originally Posted by
spirit
try to cahnge coloro of line in code above, for example use Qt::red.
or if you have possibility to attach all you code then it would be nice. :)
Thanks! Now I find the problem. I miss to tranform the coordinate points. the points are outside the dialog.
Thanks You all!
Can you show me some technology to debug a program. I found the problem using a QMessage. It's troublesome bussiness. If I know how to debug a program. Maybe it will reduce a lot of trouble.
Thank you!
Re: Is that any problem in my this function?
read this it's not a full guide but something helpful.
Re: Is that any problem in my this function?
void qDebug ( const char * msg, ... )
Calls the message handler with the debug message msg. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the console, if it is a console application; otherwise, it is sent to the debugger.
Here, If I write a GUI program. the debug message will not send to the console, it will send to the debugger. where's the debugger? Is that to say that I should use the Qt 4.4.3 (Build Debug Libraries) console to compile the program?
The header file <QtGlobal> contains some debugging macros and #defines.
Three important macros are:
* Q_ASSERT(cond), where cond is a boolean expression, writes the warning "ASSERT: 'cond' in file xyz.cpp, line 234" and exits if cond is false.
* Q_ASSERT_X(cond, where, what), where cond is a boolean expression, where a location, and what a message, writes the warning: "ASSERT failure in where: 'what', file xyz.cpp, line 234" and exits if cond is false.
* Q_CHECK_PTR(ptr), where ptr is a pointer. Writes the warning "In file xyz.cpp, line 234: Out of memory" and exits if ptr is 0.
Here tells will send some warning, but where will the warnings send to? the console?
Thanks! Your are my great help.