I'm a beginner in QT C++, and I'm trying to print Julian day on a label_j
with respect the value mentioned in array list. I'm unable to do that. Please could you see and correct it. Thanks a lot in advance.
Current month is been fetch from the UTC, if month equal jan then print 0, month equal then print 31, month equal March then print 59 and so on until it reach December.
void MainWindow::getJulianDay()
{
int month_arr[]={0,31,59,90,120,151,181,212,243,273,304,334};
QString January, February, March, April, May, June, July, August, September, October, November, December;
QDateTime local(QDateTime::currentDateTimeUtc());
QDateTime UTC(local.toUTC());
QString month=UTC.toString("MMMM");
switch (month)
{
case January:
month=month_arr[0];
break;
case February:
month=month_arr[1];
break;
case March:
month=month_arr[2];
break;
case April:
month=month_arr[3];
break;
case May:
month=month_arr[4];
break;
case June:
month=month_arr[5];
break;
case July:
month=month_arr[6];
break;
case August:
month=month_arr[7];
break;
case September:
month=month_arr[8];
break;
case October:
month=month_arr[9];
break;
case November:
month=month_arr[10];
break;
case December:
month=month_arr[11];
break;
default: month=invalid;
break;
ui->label_j->setText(month);
}
I see two main mistakes :
First of all, your case
statement conditions are empty. You should do :
switch(variable) {
case condition1:
...
break;
case condition2:
...
break;
...
default:
...
break;
}
So, your code becomes :
switch (month);
{
case 1:
month="January";
answer=month_arr[0];
break;
case 2:
month="February";
answer=month_arr[1];
break;
...
default:
month="invalid";
break;
}
The second main problem is that ui->label_j->setText(answer);
should be out of the switch
loop. As it is currently, this statement will never be executed.
Edit : As noticed by m7913d, you have a lot of type errors. Review the type of your variables !