![]() |
2010-09-30
, 10:35
|
|
Posts: 1,637 |
Thanked: 4,424 times |
Joined on Apr 2009
@ Germany
|
#142
|
Code:void MainWindow::on_line_edit_font1_editingFinished() { if ( user inputted seven characters, which is valid ) { // do something with the valid input } elseif ( user inputted only four characters which is INVALID ) { // tell user he's bad and he should write only valid things... } }
if (ui->line_edit_font1->text().length() == 7) { // do something with the valid input } elseif (ui->line_edit_font1->text().length() == 4) { // tell user he's bad and he should write only valid things... }
![]() |
2010-09-30
, 10:39
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#143
|
But how can the user enter invalid short text?Code:if (ui->line_edit_font1->text().length() == 7) { // do something with the valid input } elseif (ui->line_edit_font1->text().length() == 4) { // tell user he's bad and he should write only valid things... }
I don't know how this qtvalidator work, but isn't that
enough to prevent the short text?
regards
Nicolai
![]() |
2010-09-30
, 10:43
|
|
Posts: 199 |
Thanked: 156 times |
Joined on May 2010
@ Holland
|
#144
|
QRegExp regexer("^\\#[0-9a-fA-F]{6,6}$");
ui->line_edit_font1->setValidator(new QRegExpValidator(regexer, ui->line_edit_font1);
![]() |
2010-09-30
, 10:43
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#145
|
![]() |
2010-09-30
, 10:49
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#146
|
I think you need to make it this way:
^ = from the start of the stringCode:QRegExp regexer("^\\#[0-9a-fA-F]{6,6}$");
(.. your characters ..)
$ = until the end of the string
Also, you might consider this:
I think the parent is wrong, you have it on "this", which is the whole class, I think you need to put it on the QLineEdits specifically.Code:ui->line_edit_font1->setValidator(new QRegExpValidator(regexer, ui->line_edit_font1);
Edit: this way, you don't have to make "actualvalidator".
![]() |
2010-09-30
, 10:58
|
|
Posts: 1,637 |
Thanked: 4,424 times |
Joined on Apr 2009
@ Germany
|
#147
|
I think you need to make it this way:
^ = from the start of the stringCode:QRegExp regexer("^\\#[0-9a-fA-F]{6,6}$");
(.. your characters ..)
$ = until the end of the string
... The match is made against the entire string, e.g. if the regexp is [A-Fa-f0-9]+ it will be treated as ^[A-Fa-f0-9]+$.
![]() |
2010-09-30
, 10:58
|
Posts: 180 |
Thanked: 76 times |
Joined on May 2010
|
#148
|
![]() |
2010-09-30
, 11:00
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#149
|
Maybe you can use void QLineEdit::editingFinished () signal.
This signal is emitted when the Return or Enter key is pressed or the line edit loses focus. Note that if there is a validator() or inputMask() set on the line edit and enter/return is pressed, the editingFinished() signal will only be emitted if the input follows the inputMask() and the validator() returns QValidator::Acceptable.
The input is valid if the signal is emitted.
![]() |
2010-09-30
, 11:04
|
|
Posts: 1,637 |
Thanked: 4,424 times |
Joined on Apr 2009
@ Germany
|
#150
|
I need some help with validating user input and then do actions based on if the input is valid or not.
So far I'm good with validating the input, the validator allows me only to input correctly formatted stuff. What it doesn't check is if the input length is enough. What I don't know is how to know later if the input was long enough or not.
Here's what I do when program launches (I create the validator and set it to line edits):
If you're rich and you think I deserve a cold beer, you may donate one or two :-P
80's style stadium rock is back - FIRENOTE
Hi-Octane heavy metal - FORCE MAJEURE
Last edited by d-iivil; 2010-09-30 at 10:11.