Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to validate TextEdit Input and launch Virtual keypad

From Wiki
Jump to: navigation, search
Article Metadata
Created: sapur (24 Feb 2011)
Last edited: hamishwillee (11 Oct 2012)


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


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.


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.");
/* !
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.

QEvent event(QEvent::RequestSoftwareInputPanel);
QCoreApplication::sendEvent(this, &event);
This page was last modified on 11 October 2012, at 01:17.
87 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.