c++ - getting value from QSpinBox created in a QFormLayout -


i wondering how refer qspinbox s created code

     qformlayout* layout = new qformlayout;      layout->addrow(new qlabel(tr("board size")), new qspinbox);      layout->addrow(new qlabel(tr("number of \nstarting moves")), new qspinbox);      layout->addrow(new qlabel(tr("seed value")), new qspinbox); 

this in void function creates form layout, applies qwidget f , sets f widget qdockwidget added qmainwindow.

i need use values in qspinboxs running function, have no clue how differentiate between or reference boxes. know qspinboxs have value() function, how call on each different box?

sorry if using qt in unusual manner, new qt programming. also, not want use visual programming, want code everything. in advance!

first of - creating widgets without specifying parent potential memory leak, shouldn't it, unless know doing.

second of all, if want use value in class - should make pointer member of class , address name (like aliceljm did).

also, can use void qformlayout::addrow ( const qstring & labeltext, qwidget * field ) in order, not create labels manually (if don't need direct access them).

summing above, final code should contain:

widget.h

protected:     qspinbox *mboardsizespinbox;     qspinbox *mnumberofmovesspinbox;     qspinbox *mspeedvaluespinbox; 

widget.cpp

mboardsizespinbox = new qspinbox(this); mnumberofmovesspinbox = new qspinbox(this); mspeedvaluespinbox = new qspinbox(this);  qformlayout* layout = new qformlayout(this); layout->addrow(tr("board size"), mboardsizespinbox); layout->addrow(tr("number of \nstarting moves"), mnumberofmovesspinbox); layout->addrow(tr("seed value"), mspeedvaluespinbox);  // ... using  int speedvalue = mspeedvaluespinbox->value(); 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -