QTime 在 linux 和 windows 平台上表现不同

QTime behaving different in linux and windows platforms

我有相同的 Qt 代码,它在 linux 和 windows 中运行。但它在每种情况下的表现都不同。 在 linux 中它的行为是正确的,但在 windows 中则不是。

您可以看到,在 windows 平台中,它返回空字符串,而在 linux 平台中,它的行为符合预期。可能是什么原因?

默认构造函数 QTime produces an invalid time, most operations on an invalid time will fail or return another invalid time. Calling addSecs still leaves you with an invalid time and calling toString 无效时 returns 一个空字符串。

要构造 QTime 午夜,您需要使用:

QTime time(0,0);