View Single Post
d-iivil's Avatar
Posts: 2,154 | Thanked: 2,186 times | Joined on Dec 2009 @ Hellsinki, Finland
#141
Hi again guys.

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):
Code:
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    progress(tr("Setting up the theme, please wait..."), tr("Abort"), 0, 0, this),
    progress2(tr("Searching and importing fonts, please wait..."), tr("Abort"), 0, 0, this),
    colors()
{
    ui->setupUi(this);
    ui->scrollArea->setWidget(ui->widget);
    readdirs();
    oldfonts();
    readSettings();
    QRegExp regexer("\\#[0-9a-fA-F]{6,6}");
    QValidator* actualvalidator;
    actualvalidator = new QRegExpValidator(regexer, this);
    //QRegExpValidator validator();
    ui->line_edit_font1->setValidator(actualvalidator);
    ui->line_edit_font2->setValidator(actualvalidator);
    ui->line_edit_font3->setValidator(actualvalidator);
    ui->line_edit_font4->setValidator(actualvalidator);
    ui->line_edit_font5->setValidator(actualvalidator);
    ui->line_edit_font6->setValidator(actualvalidator);
}
How can I check in some slot later if the input is valid and if it's not, then do some actions. Like:
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 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.