Created
June 13, 2019 04:43
-
-
Save Atsushi4/767bac649d7967621627fee361743bce to your computer and use it in GitHub Desktop.
JSONの日時文字列をQDateTimeで取り出すサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QtCore/QCoreApplication> | |
#include <QtCore/QJsonObject> | |
#include <QtCore/QJsonDocument> | |
#include <QtCore/QJsonValue> | |
#include <QtCore/QDateTime> | |
#include <QtCore/QDebug> | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
auto root = QJsonDocument::fromJson(R"({"data":"2019-03-28T10:30:00+09:00"})").object(); | |
auto date = root.value("data").toVariant().toDateTime(); | |
qDebug() << date; | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Qt5.6以前だと QJsonValue::value(QLatin1String) が無いのでwarning出る人はQStringLitertal。