c++ - Updating QGridLayouts -


hi guys i'm coding game studies , i've big problems (my leg injured , couldn't go lessons).

my job simple battleships game in c++, qt.

i'm in point logic code done, gui big mess. here's code gui .cpp file:

#include <qtwidgets> #include "dialog.h"  dialog::dialog() {     creategraczbox();     createkomputerbox();     createodpowiedz();      qgridlayout *mainlayout = new qgridlayout;     mainlayout->addwidget(graczbox , 0 , 0 );     mainlayout->addwidget(komputerbox , 0 , 1 );     mainlayout->addwidget(odpowiedz , 0 , 2 );     setlayout(mainlayout);      setfixedsize(800,400);     setwindowtitle(tr("battleships!"));  }  void dialog::creategraczbox() {     graczbox = new qgroupbox(tr("gracz"));     qgridlayout *layout = new qgridlayout;      (int j = 0; j < numgridrows; ++j) {             labels[j] = new qlabel(tr("%0").arg(j+1));             layout->addwidget(labels[j], 0 , j + 1 , qt::alignleft);     }      (int = 0; < numgridrows; ++i) {             labels[i] = new qlabel(tr("%0").arg(i + 1));             layout->addwidget(labels[i], + 1, 0);     }      for(int g = 1;g<10;++g)     {         layout->setcolumnstretch(g,1);     }     graczbox->setlayout(layout); }  void dialog::createkomputerbox() {     komputerbox = new qgroupbox(tr("komputer"));     qgridlayout *layout = new qgridlayout;      (int j = 0; j < numgridrows; ++j) {             labels[j] = new qlabel(tr("%0").arg(j+1));             layout->addwidget(labels[j], 0 , j + 1 );     }      (int = 0; < numgridrows; ++i) {             labels[i] = new qlabel(tr("%0").arg(i + 1));             layout->addwidget(labels[i], + 1, 0);     }      for(int g = 1;g<10;++g)     {         layout->setcolumnstretch(g,1);     }    komputerbox->setlayout(layout); }  void dialog::createodpowiedz() {     odpowiedz = new qgroupbox(tr("komendy"));     qformlayout *layout = new qformlayout;      xlabel = new qlabel;     qpushbutton *zmienna_x_przycisk = new qpushbutton(tr("x"));     connect(zmienna_x_przycisk, signal(clicked()), this, slot(setx()));      ylabel = new qlabel;     qpushbutton *zmienna_y_przycisk = new qpushbutton(tr("y"));     connect(zmienna_y_przycisk, signal(clicked()), this, slot(sety()));      xlabel->settext(tr("aktualne x: %1").arg(zmienna_x));     ylabel->settext(tr("aktualne y: %1").arg(zmienna_y));      layout->addrow(xlabel);     layout->addrow(zmienna_x_przycisk);     layout->addrow(ylabel);     layout->addrow(zmienna_y_przycisk);     odpowiedz->setlayout(layout); }  void dialog::setx() {     bool ok_x;         x = qinputdialog::getint(this, tr("podaj x:"),                                      tr(""), 1, 1, 10, 1, &ok_x);         if (ok_x)             x=zmienna_x; }  void dialog::sety() {     bool ok_y;         y = qinputdialog::getint(this, tr("podaj y:"),                                      tr(""), 1, 1, 10, 1, &ok_y);         if (ok_y)             y=zmienna_y; } 

they way should work:

  1. i'm choosing x , y clicking on it.
  2. choosing numbers in new window.
  3. they should appear in "aktualne x:/y:".
  4. when i've x , y, click ok button (he's not there now).
  5. computer checking numbers marking in space komputer / gracz.
  6. reset x , y 0.
  7. show text "you missed. computer missed."
  8. go on till one'll win.

but don't know how make layout updating other actions. can't make dowhile work here.

you need use signals , slots here. create "ok" button , connect function, used handle x , y variables.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -