Is there a way i can get the difference between two QDates
-
Thank you for your effort in answering.
I am trying to put the code as mentioned below, but it throws me an error. Can you please help me in this?@QString expt = qry->value(2).toString();
QDate extract(QDate::fromString(expt, "MM/dd/yyyy"));
int month = (QDate::month(extract)); //throws error here
ui->lineEdit_expt->setText(month);@ -
Thank you for your effort in answering.
I am trying to put the code as mentioned below, but it throws me an error. Can you please help me in this?@QString expt = qry->value(2).toString();
QDate extract(QDate::fromString(expt, "MM/dd/yyyy"));
int month = (QDate::month(extract)); //throws error here
ui->lineEdit_expt->setText(month);@ -
@
QString expt = qry->value(2).toString();
QDate extract(QDate::fromString(expt, "MM/dd/yyyy"));
int month = extract.month();
ui->lineEdit_expt->setText(month);
@
That should work, but I have just changed your source and did not compile. So, plesae check.In addition a friendly recommendation:
Qt is mainly based on C++. It is recommended to have a sound understanding of C++ basics and how to use it. In my opinion you would benefit from working through a "tutorial for C++":http://www.tutorialspoint.com/cplusplus/. There are many other tutorials like this around. -
@
QString expt = qry->value(2).toString();
QDate extract(QDate::fromString(expt, "MM/dd/yyyy"));
int month = extract.month();
ui->lineEdit_expt->setText(month);
@
That should work, but I have just changed your source and did not compile. So, plesae check.In addition a friendly recommendation:
Qt is mainly based on C++. It is recommended to have a sound understanding of C++ basics and how to use it. In my opinion you would benefit from working through a "tutorial for C++":http://www.tutorialspoint.com/cplusplus/. There are many other tutorials like this around. -
Thank you, it worked.
I appreciate your suggestion. -
Thank you, it worked.
I appreciate your suggestion. -
I an application I am using the extracted month from Qdate and then to match it with "month" specified in a combobox. There are multiple database entries for a month, but in the output "tableview" only the last matching row is displaying. Below is the code I wrote.
Can somebody tell me if there is any mistake in the logic?@QString filter_month = ui->comboBox_month->currentText();
QString filter_year = ui->comboBox_year->currentText();conn.connopen(); QSqlQuery * qry = new QSqlQuery(); qry->prepare("select class_date from schedule_class"); if(qry->exec()) { while(qry->next()) { QString expt = qry->value(0).toString(); QSqlQueryModel * modal = new QSqlQueryModel(); QDate extract(QDate::fromString(expt, "MM/dd/yyyy")); int m = extract.month(); QString month = QString::number(m); int y = extract.year(); QString year = QString::number(y); if(month == filter_month and year == filter_year) { QSqlQuery * qry2 = new QSqlQuery(); qry2->prepare("select * from schedule_class where class_date='"+expt+"'"); qry2->exec(); modal->setQuery(* qry2); } ui->tableView_classes->setModel(modal); } conn.connclose(); }
@
-
I an application I am using the extracted month from Qdate and then to match it with "month" specified in a combobox. There are multiple database entries for a month, but in the output "tableview" only the last matching row is displaying. Below is the code I wrote.
Can somebody tell me if there is any mistake in the logic?@QString filter_month = ui->comboBox_month->currentText();
QString filter_year = ui->comboBox_year->currentText();conn.connopen(); QSqlQuery * qry = new QSqlQuery(); qry->prepare("select class_date from schedule_class"); if(qry->exec()) { while(qry->next()) { QString expt = qry->value(0).toString(); QSqlQueryModel * modal = new QSqlQueryModel(); QDate extract(QDate::fromString(expt, "MM/dd/yyyy")); int m = extract.month(); QString month = QString::number(m); int y = extract.year(); QString year = QString::number(y); if(month == filter_month and year == filter_year) { QSqlQuery * qry2 = new QSqlQuery(); qry2->prepare("select * from schedule_class where class_date='"+expt+"'"); qry2->exec(); modal->setQuery(* qry2); } ui->tableView_classes->setModel(modal); } conn.connclose(); }
@
-
You should place a new topic.
Go into a forum "eg Generanl and Desktop.":http://qt-project.org/forums/viewforum/10/ and press "Start new discussion"
Choose describing a bit your problem. This will probably better attract readers for helping. "There are also the forum rules available":http://qt-project.org/wiki/ForumHelp -
You should place a new topic.
Go into a forum "eg Generanl and Desktop.":http://qt-project.org/forums/viewforum/10/ and press "Start new discussion"
Choose describing a bit your problem. This will probably better attract readers for helping. "There are also the forum rules available":http://qt-project.org/wiki/ForumHelp -
QDate cdat=QDate::currentDate();
QString cur=QVariant(cdat.toJulianDay()).toString();
QString exp=QVariant(QVariant(expdtcal).toDate().toJulianDay()).toString();
int diff=QVariant(exp).toInt()-QVariant(cur).toInt();
if((QVariant(expdtcal).toDate()).toJulianDay() - cdat.toJulianDay() <= 0)
{
//Don't add medicine
qDebug()<<"Expired";
}