c++ - QInputDialog and QMessageBox -


i'm doing preparation exam using qt framework , know how use qinputdialog , qmessagebox in basic way (my exams hand written coding)

the qt api confusing understand when comes using , fine projects because accomplish wanted in "hacky" way set book on subject poorly laid out...

let me point, clean way of using qinputdialog , qmessagebox in scenario:

#include <qapplication> #include <qinputdialog> #include <qdate> #include <qmessagebox>  int computeage(qdate id) {   int years = qdate::currentdate().year() - id.year();   int days = qdate::currentdate().daysto(qdate               (qdate::currentdate().year(), id.month(), id.day()));   if(days > 0)      years--;   return years }  int main(int argc, char *argv[]) {   qapplication a(argc, argv);   /*  want qinputdialog , messagebox in here somewhere */   return a.exec(); } 

for qinputdialog want user give birth date (don't worry input validation) want use qmessagebox show user's age

i don't understand parameters need go qinputdialog , qmessagebox in basic case because there don't seem examples out there.

how accomplish this?

you can like:

int main(int argc, char *argv[]) {     qapplication app(argc, argv);      bool ok;     // ask birth date string.     qstring text = qinputdialog::gettext(0, "input dialog",                                          "date of birth:", qlineedit::normal,                                          "", &ok);     if (ok && !text.isempty()) {         qdate date = qdate::fromstring(text);         int age = computeage(date);         // show age.         qmessagebox::information (0, "the age",                                   qstring("the age %1").arg(qstring::number(age)));     }     [..] 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -