Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos QDateTime未使用不同的构造函数正确设置_Macos_Qt - Fatal编程技术网

Macos QDateTime未使用不同的构造函数正确设置

Macos QDateTime未使用不同的构造函数正确设置,macos,qt,Macos,Qt,我有一个返回QDateTime类的函数,其代码如下: QDateTime Foo:IntToQDateTime( int Date ) { int Second = 4, Minute = 3, Hour = 22, Day = 10, Month = 11, Year = 2011; QDate d(Year, Month, Day); QTime t(Hour, Minut

我有一个返回QDateTime类的函数,其代码如下:

QDateTime Foo:IntToQDateTime( int Date )
{
    int Second = 4,
        Minute = 3,
        Hour   = 22,
        Day    = 10,
        Month  = 11,
        Year   = 2011;
    QDate d(Year, Month, Day);
    QTime t(Hour, Minute, Second);
    QDateTime r(d, t);
    return r;
}
这就产生了r,其中空字符串/time_t为4294967295,而d和t都是精确的

如果我将代码更改为:

QDateTime Foo:IntToQDateTime( int Date )
{
    int Second = 4,
        Minute = 3,
        Hour   = 22,
        Day    = 10,
        Month  = 11,
        Year   = 2011;
    QDate d(Year, Month, Day);    // November 11 2011
    QTime t(Hour, Minute, Second);// 22:03:04:00
    QDateTime r(QDate(Year, Month, Day), QTime(Hour, Minute, Second));
    return r;
}

r现在是11月8日星期五00:56:47 16182,时间为4294967295,与上述时间相同。谁能给我解释一下为什么a。QDateTime类r的日期/时间不准确,原因是b。通过与QDate…,QTime…相关的d和t。。。构造函数中的值也会影响日期/时间。

您是如何确定报告的值的

通过此程序:

#include <QCoreApplication>
#include <QDebug>
#include <QDate>
#include <QTime>

QDateTime IntToQDateTime( int Date )
{
    int Second = 4,
        Minute = 3,
        Hour   = 22,
        Day    = 10,
        Month  = 11,
        Year   = 2011;
    QDate d(Year, Month, Day);
    QTime t(Hour, Minute, Second);
    QDateTime r(d, t);
    return r;
}

int main(int argc, char** argv)
{
  QCoreApplication a(argc, argv);
  QDateTime t = IntToQDateTime(0);
  qDebug() << t.toTime_t();
  qDebug() << t.toString();
  return 0;
}

您是否确定您的环境是正确的,并且没有看到调试的瑕疵?

我相信您是对的。我发誓昨天晚上它甚至在输出上都没有正常工作,但现在它是!看来这是调试的产物。谢谢你的帮助。
1320958984
"Do 10. Nov 22:03:04 2011"