diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..23c6517 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.o +*.exe +.qmake.stash +Makefile +qml-validator diff --git a/README.md b/README.md new file mode 100644 index 0000000..5763709 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# QML Validator + +QML Validator is a small utility which simply loads the input file and show any +errors that could occur when doing so. It uses QCoreApplication, and as such it +doesn't require a graphical environment to run, as opposed to qmlscene for +example, and as such may be used in situation where a graphical environment +isn't available, such as a continuous integration script. + +## Usage + +``` +qml-validator +``` diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..c035335 --- /dev/null +++ b/main.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +std::ostream& operator<<(std::ostream& os, const QString s){ + return os << s.toStdString(); +} + +int main(int argc, char** argv){ + if(argc < 2){ + std::cout << "Usage: qml-validator " << std::endl; + return 1; + } + + QCoreApplication app(argc, argv); + QQmlEngine engine; + QQmlComponent component(&engine); + QObject::connect(&component, &QQmlComponent::statusChanged, + [&component, argv](QQmlComponent::Status status){ + if(status == QQmlComponent::Status::Null){ + std::cout << "Component is Null." << std::endl; + }else if(status == QQmlComponent::Status::Ready){ + // OK! + }else if(status == QQmlComponent::Status::Loading){ + std::cout << "Component is Loading." << std::endl; + }else if(status == QQmlComponent::Status::Error){ + std::cout << "Errors happened while loading " << argv[1] + << ": " << std::endl; + for(QQmlError error : component.errors()){ + std::cout << error.toString() << std::endl; + } + exit(1); + } + }); + component.loadUrl(QUrl(argv[1])); +} diff --git a/qml-validator.pro b/qml-validator.pro new file mode 100644 index 0000000..cda6277 --- /dev/null +++ b/qml-validator.pro @@ -0,0 +1,3 @@ +QT += qml + +SOURCES += main.cpp