Namespaces
Variants
Actions

How to validate TextEdit Input and launch Virtual keypad

Jump to: navigation, search
Article Metadata

Article
Created: sapur (24 Feb 2011)
Last edited: hamishwillee (11 Oct 2012)

Overview

This article explains how to validate TextEdit Input and launch Virtual keypad from Qt Application

Description

This article describes how to handle the requirement if the virtual keypad needs to be launched from the code.

Below descriprtion is the use case in which launching of keypad is required.

A form is created using QTextEdit and QDateEdit. After each entry:

1. The entry should be validated.

2. If the entry is not valid, an error pop up should be displayed.

3. When "Ok" is pressed on error dialog, the virtual keyboard should be invoked on the invalid field giving the user an opportunity to correct the mistake.

4. If the entry is valid then the virtual keypad does not need to be launched.

Solution

First validate the entry.

 //   To activate validation when input is entered.
QObject::connect(currentDateEdit, SIGNAL(editingFinished()), this, SLOT(validate()));
 
 
// To validate the text of DateEdit
// *1.Set a constant for minimum value; in this case MinYear.
// *2.Get the value entered in DateEdit field.
// *3.If the entered year (setYear) is less than the minimum year (MinYear),
// display an error message and launch the keypad.
 
const int MinYear(2011);
int setYear = currentDateEdit->date().year();
QDate setDate = currentDateEdit->date();
 
if (setYear < MinYear) {
 
// The entry is invalid!
 
QMessageBox msgBoxErr;
msgBoxErr.setText("Invalid year,the minimum is 2011.");
msgBoxErr.exec();
launchKeypad();
}
 
 
/* !
Sets the focus on the input field and launches the virtual keypad.
To launch the keypad, an event with type QEvent::RequestSoftwareInputPanel is sent to the core application.
*/

launchKeypad()
{
this->setFocus();
QEvent event(QEvent::RequestSoftwareInputPanel);
QCoreApplication::sendEvent(this, &event);
}
This page was last modified on 11 October 2012, at 04:17.
198 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved