Ejemplo n.º 1
0
QVariant DaysModel::data(const QModelIndex &index, int role) const
{
    int month = 1;
    int daysCount = 0;
    int day = 0;
    for(month=1; month<=12;month++)
    {
        if(index.row() + 1 - daysCount - QDate(QDate::currentDate().year(),month,1).daysInMonth() <= 0)
        {
            day = index.row() + 1 - daysCount;
            break;
        }
        daysCount += QDate(QDate::currentDate().year(),month,1).daysInMonth();
    }

    QDate date(QDate::currentDate().year(), month, day);

    if (role == Qt::DisplayRole)
    {
        if(index.column() == 0)
        {
            return date;
        }
        else
        {
            int seconds = calculateHours(date);
            QTime time(seconds/3600, (seconds%3600)/60, (seconds%3600)%60);
            return time.toString("hh:mm:ss");
        }
    }

    return QVariant();
}
Ejemplo n.º 2
0
int main(void)
{
      printf("Enter the amount of kilometers you ran.\n");

      /* Get the distance in kilometers. */
      scanf("%lf", &kms);
      /* Convert the distance to miles. */
      miles = MILES_PER_KMS * kms;

      /* Display the distance in miles. */
      printf("That equals %.2f miles.\n", miles);
      
      calculateHours(miles); /* The argument being passed into the function does not have to match the name of the parameters in the function. */
      /* Calls the function that performs the conversion */

      return (0);
}