2
* Copyright 2014 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* QML launcher with the ability to setup the QQuickView/ QQmlEngine differently
18
* Rationale: Different variants of qmlscene exist as well as C++ and Go apps
19
* This is to write Autopilot test cases that exhibit specific behavior
23
#include <QtCore/qdebug.h>
24
#include <QtQuick/QQuickView>
25
#include <QtGui/QGuiApplication>
26
#include <QtQml/QQmlEngine>
27
#include <QtQml/QQmlContext>
28
#include <QtCore/QFileInfo>
30
#include <QOpenGLContext>
31
#include <QtGui/private/qopenglcontext_p.h>
32
#include <QtQuick/private/qsgcontext_p.h>
36
QString self(QGuiApplication::instance()->arguments().at(0));
37
std::cout << "Usage\n "
39
<< " -testability -frameless -engine"
40
<< " --desktop_file_path=DESKTOP_FILE"
41
<< " -I MODULE_PATH FILENAME\n";
45
int main(int argc, const char *argv[])
47
// QPlatformIntegration::ThreadedOpenGL
48
setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
49
// QPlatformIntegration::BufferQueueingOpenGL
50
setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
51
// Oxide and QWebEngine need a shared context
52
QScopedPointer<QOpenGLContext> shareContext;
53
shareContext.reset(new QOpenGLContext);
54
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
55
QSGContext::setSharedOpenGLContext(shareContext.data());
57
QOpenGLContextPrivate::setGlobalShareContext(shareContext.data());
59
QGuiApplication::setApplicationName("UITK Launcher");
60
QGuiApplication application(argc, (char**)argv);
61
QStringList args (application.arguments());
63
int _testability(args.indexOf("-testability"));
64
args.removeAt(_testability);
65
int _frameless(args.indexOf("-frameless"));
66
args.removeAt(_frameless);
67
int _engine(args.indexOf("-engine"));
68
args.removeAt(_engine);
70
Q_FOREACH(QString arg, args) {
71
if (arg.startsWith("--desktop_file_hint")) {
72
// This will not be used - it only needs to be ignored
73
int _desktop_file_hint(args.indexOf(arg));
74
args.removeAt(_desktop_file_hint);
78
// Testability is only supported out of the box by QApplication not QGuiApplication
79
if (_testability > -1 || getenv("QT_LOAD_TESTABILITY")) {
80
QLibrary testLib(QLatin1String("qttestability"));
82
typedef void (*TasInitialize)(void);
83
TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
87
qCritical("Library qttestability resolve failed!");
91
qCritical("Library qttestability load failed!");
97
// The default constructor affects the components tree (autopilot vis)
100
view = new QQuickView();
101
engine = view->engine();
103
engine = new QQmlEngine();
104
view = new QQuickView(engine, NULL);
107
int _import(args.indexOf("-I"));
108
args.removeAt(_import);
110
if (args.count() > _import) {
111
QString importPath(args.at(_import));
112
args.removeAt(_import);
113
engine->addImportPath(importPath);
117
view->setResizeMode(QQuickView::SizeRootObjectToView);
118
view->setTitle("UI Toolkit QQuickView");
119
if (_frameless > -1) {
120
view->setFlags(Qt::FramelessWindowHint);
123
// The remaining unnamed argument must be a filename
124
if (args.count() == 1) {
125
qCritical() << "Missing filename";
128
QString filename(args.at(1));
129
// The first argument is the launcher itself
132
QUrl source(QUrl::fromLocalFile(filename));
133
view->setSource(source);
134
if (view->errors().count() > 0) {
139
if (args.count() > 1) {
140
qCritical() << "Invalid arguments passed" << args;
144
return application.exec();