Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Is that any problem in my this function?

  1. #1
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Is that any problem in my this function?

    Qt Code:
    1. // draw plotter line using QPainter function drawPolyline
    2. void GenePlotter::drawPlotterLine(QPainter *painter)
    3. {
    4. QRect rect(Margin, Margin,
    5. width() - 2 * Margin, height() - 2 * Margin);
    6. if (!rect.isValid())
    7. return;
    8.  
    9. painter->setClipRect(rect.adjusted(+1, +1, -1, -1));
    10.  
    11. //draw best lines
    12. painter->setPen(QPen(Qt::red,1.0));
    13. const QPointF* point=bestPoints.data(); //bestPoints is a vector
    14. painter->drawPolyline(point,bestPoints.size());
    15.  
    16.  
    17.  
    18. //draw average line
    19. painter->setPen(QPen(Qt::blue,1.0)); //X is the same
    20. point=avgPoints.data(); //avgPoints is also a vector
    21. painter->drawPolyline(point,avgPoints.size());
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is that any problem in my this function?

    can you show us code where you use this method?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is that any problem in my this function?

    what is the size of avgPoints?

  5. #5
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is that any problem in my this function?

    Qt Code:
    1. void GenePlotter::refreshPixmap()
    2. {
    3. pixmap = QPixmap(size());
    4. pixmap.fill(this, 0, 0);
    5.  
    6. QPainter painter(&pixmap);
    7. painter.initFrom(this);
    8. drawGrid(&painter); // This line works perfectly good
    9.  
    10. if(couter!=0)
    11. drawPlotterLine(&painter); // here can't draw line
    12.  
    13. update();
    14. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is that any problem in my this function?

    Quote Originally Posted by talk2amulya View Post
    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.

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is that any problem in my this function?

    stupid question, but maybe couter == 0?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #8
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is that any problem in my this function?

    Qt Code:
    1. // perform one generaion evolution and update the points of the plotter
    2. void GenePlotter::execOnce()
    3. {
    4. geneGroup.performEvolution();
    5. QPointF point;
    6. point.setX(couter);
    7. point.setY(((geneGroup.getGroup())+GeneGroup::popSize)->getfitness());
    8. bestPoints.push_back(point);
    9.  
    10. point.setY(geneGroup.getAvg());
    11. // x are the same of these two point.
    12. avgPoints.push_back(point);
    13.  
    14. refreshPixmap();
    15. }
    16.  
    17.  
    18. void GenePlotter::oneStep()
    19. {
    20. ++couter;
    21. if(couter<generation)
    22. {
    23. execOnce();
    24. }
    25. }
    26.  
    27.  
    28. void GenePlotter::runAll()
    29. {
    30. settingButton->setEnabled(false);
    31. oneStepButton->setEnabled(false);
    32. runAllButton->setEnabled(false);
    33. qApp->processEvents();
    34. if(couter==0)
    35. ++couter;
    36.  
    37. while(couter<generation)
    38. {
    39. ++couter;
    40. execOnce();
    41. repaint();
    42. }
    43. settingButton->setEnabled(true);
    44. oneStepButton->setEnabled(true);
    45. runAllButton->setEnabled(true);
    46.  
    47. }
    To copy to clipboard, switch view to plain text mode 

    More code

  9. #9
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is that any problem in my this function?

    if you do this
    Qt Code:
    1. void GenePlotter::refreshPixmap()
    2. {
    3. pixmap = QPixmap(size());
    4. pixmap.fill(this, 0, 0);
    5.  
    6. QPainter painter(&pixmap);
    7. painter.initFrom(this);
    8. drawGrid(&painter); // This line works perfectly good
    9. drawPlotterLine(&painter); // here can't draw line
    10.  
    11. update();
    12. }
    To copy to clipboard, switch view to plain text mode 
    is something changed?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. #10
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is that any problem in my this function?

    Quote Originally Posted by spirit View Post
    stupid question, but maybe couter == 0?
    No, the couter will increase. I make it draw only couter >0 ;

    Qt Code:
    1. // In the construtor function
    2. connect(oneStepButton,SIGNAL(clicked()),this,SLOT(oneStep()));
    3. connect(runAllButton,SIGNAL(clicked()),this,SLOT(runAll()));
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is that any problem in my this function?

    to #9

    Fail, the same

  12. #12
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is that any problem in my this function?

    Quote Originally Posted by HelloDan View Post
    Qt Code:
    1. // draw plotter line using QPainter function drawPolyline
    2. void GenePlotter::drawPlotterLine(QPainter *painter)
    3. {
    4. QRect rect(Margin, Margin,
    5. width() - 2 * Margin, height() - 2 * Margin);
    6. if (!rect.isValid())
    7. return;
    8.  
    9. painter->setClipRect(rect.adjusted(+1, +1, -1, -1));
    10.  
    11. //draw best lines
    12. painter->setPen(QPen(Qt::red,1.0));
    13. const QPointF* point=bestPoints.data(); //bestPoints is a vector
    14. painter->drawPolyline(point,bestPoints.size());
    15.  
    16.  
    17.  
    18. //draw average line
    19. painter->setPen(QPen(Qt::blue,1.0)); //X is the same
    20. point=avgPoints.data(); //avgPoints is also a vector
    21. painter->drawPolyline(point,avgPoints.size());
    To copy to clipboard, switch view to plain text mode 

    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

  13. #13
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  14. #14
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  15. The following user says thank you to talk2amulya for this useful post:

    HelloDan (3rd April 2009)

  16. #15
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is that any problem in my this function?

    Quote Originally Posted by spirit View Post
    if you comment all code in GenePlotter::drawPlotterLine and draw some other shape, circle for example, in this case is something changed?

    Qt Code:
    1. QLineF line(QPointF(10,430),QPointF(89,520));
    2. painter->drawLine(line);
    3. // I draw a line to test, but the line didn't turn up too.
    To copy to clipboard, switch view to plain text mode 

  17. #16
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is that any problem in my this function?

    Quote Originally Posted by talk2amulya View Post
    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!

  18. #17
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  19. #18
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is that any problem in my this function?

    Quote Originally Posted by spirit View Post
    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!

  20. #19
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is that any problem in my this function?

    read this it's not a full guide but something helpful.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  21. The following user says thank you to spirit for this useful post:

    HelloDan (3rd April 2009)

  22. #20
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

Similar Threads

  1. Replies: 3
    Last Post: 12th March 2012, 01:45
  2. subclassed const function problem
    By qtneuling in forum Newbie
    Replies: 8
    Last Post: 22nd June 2008, 02:52
  3. Function confusion
    By KShots in forum General Programming
    Replies: 3
    Last Post: 26th June 2007, 21:56
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. K&R's strcpy function - problem with pointers
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 8th January 2006, 15: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.