Skip to content

Commit

Permalink
Inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LcsTen committed Apr 28, 2021
0 parents commit 337be26
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.o
*.exe
.qmake.stash
Makefile
qml-validator
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <input-file>
```
37 changes: 37 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
#include <QQmlComponent>
#include <QQmlEngine>
#include <QCoreApplication>

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 <qmlfile>" << 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]));
}
3 changes: 3 additions & 0 deletions qml-validator.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
QT += qml

SOURCES += main.cpp

0 comments on commit 337be26

Please sign in to comment.