There is a problem. A time is manually entered into QLineEdit. How to get access to the entered characters to compare them with any reference. For example, entered 05:12:00. As in a variable to display the value of the first character. Or any other.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

Use the QLineEdit::text() method, which will return a class object of the QString string. And from it, access to any of the characters can be obtained through the QString::at() method or the QString::operator[] .

Example:

 QLineEdit *ledit = new QLineEdit(this); // ... ввод данных пользователем ... // Получение содержимого поля ввода. QString txt = ledit->text(); // Посимвольный вывод строки. for(int i = 0; i < txt.size(); ++i) qDebug() << txt[i]; 

If it is assumed that the date and / or time will be entered in the input field, then you can use the appropriate widgets, such as QDateTimeEdit and QDateEdit . They have already implemented all the necessary functionality for parsing and checking user input.