Unsolved Help me write code to checkbox
-
I created array QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
And check box. When activating the checkbox, I want to add characters, for example $ to the array, to get ----> QString possibleCharacters ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 $$$");Who can write such code to the checkbox_ statechanged(int arg1).............And when the tick is not activated, return QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); -
@Qwerty123098
Slots do not "return" any value.void SomeClass::checkbox_statechanged(int arg1) { QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); if (arg1 == Qt::Checked) possibleCharacters += "$$$"; }
All you had to do is test your
arg1
againstQt::Checked
, which should be pretty clear from the documentation.If that's not what you mean, try to express your question better.
-
@JonB Спасибо большое👍
-
@Qwerty123098 Google translate says: Добро пожаловать ;-) I don't speak Russian
-
Thank you
-
if you uncheck how to write so that those characters are removed from the array
-
@Qwerty123098 said in Help me write code to checkbox:
that those characters are removed from the array
Which characters?
Please read documentation: https://doc.qt.io/qt-5/qstring.html#remove-1 -
@jsulm given my first question the $ character
-
If you know all characters that should be added, when you activate your checkbox, you could use 2 different strings or arrays. One WITH special characters like
$
or&
and one WITHOUT. Then you just replace the content of your array or just use the 2nd array. So you dont have to manipulate.Something like this will work too:
QString currentValidChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); // could be a member variable void SomeClass::checkbox_statechanged(int arg1) { QString chars = currentValidChars; if (arg1 == Qt::Checked) chars += "$$$"; else // "else" case means, that state changed from "checked" to unchecked // just use unchanged array }
@JonB I took the liberty to steal your function and modify it to anwer OPs 2nd question :-)
@Qwerty123098 If your checkBox was not checked before, just use the standard array without special chars. With @JonB s slot and my modification you can toggle between normal char set and your special characters
-
Thank you
-
unchcanged array is possibleCharacters -= "$$$"; ?
-
No this is not possible.
Just the array without adding your special characters.
(A-Z,a-z,0-9)