C++ 如何在QTimeEdit中读取QTimeEdit中的当前时间?
如何在Qt中的C++ 如何在QTimeEdit中读取QTimeEdit中的当前时间?,c++,qt,C++,Qt,如何在Qt中的QTimeEdit中读取用户设置的当前小时和分钟,以及如何在QDateTime中执行此操作(读取当前日期、月份、年份、分钟和小时)您可以按如下方式读取QTimeEdit的时间: QTimeEdit* timeEdit = new QTimeEdit(); // created the object // write code to initialize QTimeEdit as per your requirement // Put below code where
QTimeEdit
中读取用户设置的当前小时和分钟,以及如何在QDateTime
中执行此操作(读取当前日期、月份、年份、分钟和小时)您可以按如下方式读取QTimeEdit
的时间:
QTimeEdit* timeEdit = new QTimeEdit(); // created the object
// write code to initialize QTimeEdit as per your requirement
// Put below code wherever you want to read QTimeEdit Data
QTime enTime = timeEdit->time() // Read the Current time from QTimeEdit Object
qDebug() << enTime.toString(); // Printing time in Console
QTimeEdit*timeEdit=new QTimeEdit();//创建对象
//根据您的要求编写初始化QTimeEdit的代码
//将下面的代码放在您想要读取QTIMEDIT数据的任何位置
QTime enTime=timeEdit->time()//从QTimeEdit对象读取当前时间
qDebug()使用time()
和date()
方法:
const int hour = timeEdit->time().hour();
const int minute = timeEdit->time().minute();
const int day = dateEdit->date().day();
const int month = dateEdit->date().month();
const int year = dateEdit->date().year();
请查看QTimeEdit和QDateTime的Qt文档。它很好地涵盖了这些主题谢谢,它帮助了我:)还支持timeEdit->time().second()@当然可以。我在回答中没有提到其他单位,因为它们在原始问题中不存在。