0

私は NetBeans + Qt + MinGW を持っています。

私のプログラムで何が起こっているのか教えてください。QtGlass.cpp の最初のループにブレークポイントを設定しました (以下のコメントでブレークポイントとマークされています)。 Arrow_nキーを押すイベントを表す int です。矢印キーを押したときにフィギュアをペイントしたいだけです。

さて、私は外側のループにいます。

i = 5
Falcon.get_x()+Falcon.get_width() = 7

それから私は内側のループにいます。

j = 5
Falcon.get_y()+Falcon.get_height() = 7

内側のループの次の反復時Falcon.get_x() = 261。内側のループの次の反復時Falcon.get_x() = 65797

デバッグを停止して再度開始すると、同じ数値が得られます。したがって、これらの 261 と 65697 の表示方法には一定の規則性があります。しかし、それ以来変わっていないのでcurrent_x、どうしてそれができるのかは私には謎です. current_yそれらを変更するための設定方法さえありません。

何が起こっているのか理解するのを手伝ってもらえますか?

次に、デバッグを開始します。

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) {
        for (int i = Falcon.get_x(); i < (Falcon.get_x()+Falcon.get_width()); i++){ //Breakpoint.
            for (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));
                }
            }
        }
    }
4

0 に答える 0