#includeint main(int argc, char *argv[]) { QApplication app(argc, argv); QCheckBox checkbox("Option 1"); // create a checkbox with text "Option 1" checkbox.setText("Select Option 1"); // change the text to "Select Option 1" checkbox.show(); // show the checkbox return app.exec(); }
#includeIn this example, we create a QCheckBox that is initially checked, and set the text to "I agree to the terms and conditions". The QCheckBox widget belongs to the Qt Widgets module, which is part of the Qt Core library. Therefore, we need to include the appropriate header files and link against the Qt Core library to use it in our project.int main(int argc, char *argv[]) { QApplication app(argc, argv); QCheckBox checkbox; checkbox.setChecked(true); // set the checkbox to checked checkbox.setText("I agree to the terms and conditions"); // set the text checkbox.show(); return app.exec(); }