Results 1 to 2 of 2

Thread: how to take input date from user in qdateedit and show database accordingly

  1. #1
    Join Date
    May 2014
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default how to take input date from user in qdateedit and show database accordingly

    how to take input any date from user in qdateedit or calenderwidget and show database accordingly by clicking button now my code is showing databse of only current
    Qt Code:
    1. void MainWindow::on_pushButton_2_clicked()
    2. {
    3. QDateEdit *dateedit=new QDateEdit;
    4.  
    5.  
    6. QDate d=calendar->selectedDate();
    7. ui->dateEdit->setDate(d);
    8.  
    9.  
    10. int q= d.year();
    11. QString q1=QString::number(q);
    12. int q2=d.month();
    13. QString q3=QString::number(q2);
    14. int q4=d.day();
    15. QString q5=QString::number(q4);
    16.  
    17. QSqlQueryModel *mode =new QSqlQueryModel(ui->print);
    18. mode->setQuery(QString("select * from health10 where month(Datestamp)=\""+q3+"\" and day(Datestamp)=\""+q5+"\" and year(datestamp)=\""+q1+"\" ;"));
    19. ui->print->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
    20. ui->print->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
    21. ui->print-> setModel (mode);date(todays date) i want user to selct date and show data of that particular date
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 3rd May 2014 at 16:43. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to take input date from user in qdateedit and show database accordingly

    If you want the user to enter a date, you need to give the user an opportunity to do so.

    Show the calendar widget and connec to one of its selectionChanged() signal and then proceed with the selected date.

    Cheers,
    _

Similar Threads

  1. QDateTimeEdit (QTimeEdit, QDateEdit) invalid input
    By Kumosan in forum Qt Programming
    Replies: 10
    Last Post: 15th June 2012, 12:21
  2. Replies: 6
    Last Post: 13th July 2011, 19:10
  3. User Input using QString
    By kumarpraveen in forum Newbie
    Replies: 4
    Last Post: 9th July 2010, 07:49
  4. QDateEdit and date returned
    By cydside in forum Qt Programming
    Replies: 17
    Last Post: 26th May 2009, 21:08
  5. QDateEdit and empty date
    By vieraci in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2007, 16:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.