c++ - Private variables somehow mysteriously change -
i have netbeans + qt + mingw.
could tell me going on in program. put breakpoint @ first loop in qtglass.cpp (marked breakpoint in comments below). arrow_n
int signifying event of pressing key. want figure painted if press arrow key.
well, i'm in outer loop.
i = 5 falcon.get_x()+falcon.get_width() = 7
then i'm in inner loop.
j = 5 falcon.get_y()+falcon.get_height() = 7
at next iteration of inner loop falcon.get_x() = 261
. @ next iteration of inner loop falcon.get_x() = 65797
.
if stop debugging , start again, i'll same figures. so, there regularity in how these 261 , 65697 appear. how can mystery me current_x
, current_y
not changed since then. don't have setting methods changing them.
could me understand going on?
then start debugging.
figure.h
class figure: public qobject{ q_object public: bool shape[4][4]; private: int current_x; int current_y; int height; int width; public: figure(); int testint; int test[2]; int get_x(); int get_y(); int get_height(); int get_width();
figure.cpp
figure:: figure(){ current_x = 5; current_y = 5; height = 2; width = 2; } int figure:: get_x(){ return current_x; } int figure:: get_y(){ return current_y; } int figure::get_height(){ return height; } int figure::get_width(){ return width; }
qtglass.cpp
void qtglass::paintevent(qpaintevent *event) { qpainter painter(this); figure falcon; glassredraw(painter); painter.setpen(qpen(qt::red, 4)); if (arrow_n > 0) { (int = falcon.get_x(); < (falcon.get_x()+falcon.get_width()); i++){ //breakpoint. (int j = falcon.get_y(); j < (falcon.get_y()+falcon.get_height()); j++){ if (falcon.is_cell_filled(i,j)){ painter.fillrect(i * 30, j * 30, 29, 29, qbrush(qt::green, qt::solidpattern)); } } } }
Comments
Post a Comment