PDA

View Full Version : how to take input date from user in qdateedit and show database accordingly



vikchh00@gmail.com
3rd May 2014, 08:51
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


void MainWindow::on_pushButton_2_clicked()
{
QCalendarWidget *calendar=new QCalendarWidget;
QDateEdit *dateedit=new QDateEdit;


QDate d=calendar->selectedDate();
ui->dateEdit->setDate(d);


int q= d.year();
QString q1=QString::number(q);
int q2=d.month();
QString q3=QString::number(q2);
int q4=d.day();
QString q5=QString::number(q4);

QSqlQueryModel *mode =new QSqlQueryModel(ui->print);
mode->setQuery(QString("select * from health10 where month(Datestamp)=\""+q3+"\" and day(Datestamp)=\""+q5+"\" and year(datestamp)=\""+q1+"\" ;"));
ui->print->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents );
ui->print->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents );
ui->print-> setModel (mode);date(todays date) i want user to selct date and show data of that particular date

anda_skoa
3rd May 2014, 17:46
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,
_