Making a checkbox checked
-
If you want the inital state of the checkboxes to be checked and disabled either set both properties in the UI designer or manually set them right after the call to setupUi().
The most sensible approach is most probably adding two private slots enableCheckboxes() and disableCheckboxes() which contain the corresponding code and then can be connected to the QTcpSocket connected and disconnected signal.
-
y
thanks thats the good wayi try to have this method in the robbie20 (ui class)
@void Robbie20::chkbox_client()
{
ui->chkbox_client->setChecked(1);
ui->chkbox_client->isChecked();
}
@
and try to run it after initialisation in the main.cpp
but nothing get checked:@int main(int argc, char *argv[])
{
QApplication a(argc, argv);Robbie20 w; w.show(); w.loadTextFile(); w.chkbox_client();
....
}@do you c any mistake? why isn't it checked, and how can i fix it?
-
Would suggest to use QLabel with different icons/pixmaps to indicate the TCP/IP connection status like Red means no connection, Green means connected etc something like that rather than a CheckBox that is operated internally - mean it is my suggestion.
Because in your application, the CheckBox is used as a kind of indication whether TCP/IP connections is connected or not, so suggest to use some kind of Display Widgets which might add more meaning to the UI controls.
-
hi,
thanks,
i made already the gui and there are only 3 checkboxes, so its not so confusing.and i would really like to know how to make those checkboxes checked.
-
If you have void Robbie20::chkbox_client() method in Robbie20, why don't you call chkbox_client() within loadTextFile() method, which is also a method of Robbie20. Try to minimize the call in main and encapsulate them in your Concrete Class.
How about showing Robbie20 Widget once you are done with loading Text File and changing check box state.
@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Robbie20 w;w.loadTextFile(); w.chkbox_client(); w.show(); .... }
@
-
Pardon me - actually it shouldn't make any difference whether you call setChecked(1) after show() call or before. Tried a sample code, to just confirm it, and it is working for me.
Just added a CheckBox to the UI and added a method as you said and called the same after showing the widget, I see the checkbox is checked.
-
hi,
i will show screenshot when project finished, because we have to buy licence before using it on robot.ah the error was that i made the checkbox "not checkable"
but now when it is checkable, the user can uncheck it. thats not mentioned.
so i always have to
make it checkable, then check/uncheck it and then make it again uncheckable ... -
thank u guys for helping.
when i only make
@ ui->chkbox_client->setChecked(1);@
its checked, but its changable by hand - it mustn't and should be stablewhen
@ ui->chkbox_client->setChecked(1);
ui->chkbox_client->setCheckable(0);@
its not checkable by hand, but the check is removedany ideas?
-
Or just use checkbox::setEnabled(false). It will gray the widget out, though. This probably can be overridden.
-
hi,
now i have a strange problemin main.cpp
@
w.chkbox_client;@works great and set the box checked.
but also in main.cpp,
@
QObject::connect(st.socket,SIGNAL(connected()), &w, SLOT(chkbox_client()));@
doesn't work, even i see there is a signal connected emittet.i can see it because in the tcpconnect class, i put this signals out with qdebug, so i see exactly its connected.
and in my main.cpp
i have this:@
QObject::connect(st.socket,SIGNAL(readyRead()), &w, SLOT(loadTextFile() ) );@
and this works great.thankful for any hints
PS:
btw st is an object made of the class qtcpsocket, and there its made with socket = new QTcpSocket(this);
and there i have piped the connection signal out@
connect(socket,SIGNAL(connected()), this, SLOT(connected()));@where connected is a method who tells the connection via qdebug to me
general second question:
is the main.cpp the right place for those - inter class connections? -
Does st.socked return a pointer?
-
hi,
i think so,
because no errors when compiling, and when i do with
&st.socket
there is an error
@C:\Dokumente und Einstellungen\loetrobo\Robbie20-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug..\Robbie20\main.cpp:19: error: no matching function for call to 'QObject::connect(QTcpSocket**, const char*, Robbie20*, const char*)'@
looking like a double pointer so without &
it should be normal pointer