2022-05-13 13:12:05 +00:00
// Copyright (C) 2016 Research In Motion.
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
2012-12-21 23:42:47 +00:00
# include "conf.h"
# include <QCoreApplication>
2013-10-12 02:59:09 +00:00
# ifdef QT_GUI_LIB
2012-12-21 23:42:47 +00:00
# include <QGuiApplication>
2013-10-12 02:59:09 +00:00
# include <QWindow>
# include <QFileOpenEvent>
2020-01-30 14:54:09 +00:00
# include <QSurfaceFormat>
2012-12-21 23:42:47 +00:00
# ifdef QT_WIDGETS_LIB
# include <QApplication>
2013-10-12 02:59:09 +00:00
# endif // QT_WIDGETS_LIB
# endif // QT_GUI_LIB
2012-12-21 23:42:47 +00:00
# include <QQmlApplicationEngine>
2014-03-09 21:27:34 +00:00
# include <QQmlComponent>
2019-04-16 15:25:36 +00:00
# include <QCommandLineOption>
# include <QCommandLineParser>
2014-03-09 21:27:34 +00:00
# include <QDir>
2012-12-21 23:42:47 +00:00
# include <QFile>
# include <QFileInfo>
2019-04-23 13:20:15 +00:00
# include <QLoggingCategory>
2012-12-21 23:42:47 +00:00
# include <QStringList>
2015-03-11 05:25:14 +00:00
# include <QScopedPointer>
2012-12-21 23:42:47 +00:00
# include <QDebug>
# include <QStandardPaths>
2014-03-09 21:27:34 +00:00
# include <QTranslator>
2012-12-21 23:42:47 +00:00
# include <QtGlobal>
2015-06-03 09:05:12 +00:00
# include <QLibraryInfo>
2012-12-21 23:42:47 +00:00
# include <qqml.h>
# include <qqmldebug.h>
2020-01-30 14:43:57 +00:00
# include <qqmlfileselector.h>
2017-12-19 15:37:24 +00:00
# include <private/qtqmlglobal_p.h>
2022-02-25 14:49:34 +00:00
# include <private/qqmlimport_p.h>
2017-12-19 15:37:24 +00:00
# if QT_CONFIG(qml_animation)
2012-12-21 23:42:47 +00:00
# include <private/qabstractanimation_p.h>
2017-03-30 08:41:52 +00:00
# endif
2012-12-21 23:42:47 +00:00
# include <cstdio>
# include <cstring>
# include <cstdlib>
2019-09-30 08:53:49 +00:00
# include <memory>
2012-12-21 23:42:47 +00:00
2013-11-18 14:57:08 +00:00
# define FILE_OPEN_EVENT_WAIT_TIME 3000 // ms
2021-09-22 18:33:51 +00:00
Q_LOGGING_CATEGORY ( lcDeprecated , " qt.tools.qml.deprecated " )
2019-04-23 13:31:15 +00:00
enum QmlApplicationType {
QmlApplicationTypeUnknown
, QmlApplicationTypeCore
# ifdef QT_GUI_LIB
, QmlApplicationTypeGui
# ifdef QT_WIDGETS_LIB
, QmlApplicationTypeWidget
# endif // QT_WIDGETS_LIB
# endif // QT_GUI_LIB
} ;
static QmlApplicationType applicationType =
# ifndef QT_GUI_LIB
QmlApplicationTypeCore ;
# else
QmlApplicationTypeGui ;
# endif // QT_GUI_LIB
2018-02-21 09:41:54 +00:00
static Config * conf = nullptr ;
static QQmlApplicationEngine * qae = nullptr ;
2017-04-12 13:45:18 +00:00
# if defined(Q_OS_DARWIN) || defined(QT_GUI_LIB)
2013-11-18 14:57:08 +00:00
static int exitTimerId = - 1 ;
2017-04-12 13:45:18 +00:00
# endif
2023-04-26 13:15:37 +00:00
static const QString iconResourcePath ( QStringLiteral ( " :/qt-project.org/imports/QmlRuntime/Config/resources/qml-64.png " ) ) ;
static const QString confResourcePath ( QStringLiteral ( " :/qt-project.org/imports/QmlRuntime/Config/ " ) ) ;
2021-09-21 13:23:55 +00:00
static const QString customConfFileName ( QStringLiteral ( " configuration.qml " ) ) ;
2019-04-23 13:31:15 +00:00
static bool verboseMode = false ;
static bool quietMode = false ;
2021-03-18 14:10:46 +00:00
static bool glShareContexts = true ;
2023-02-02 10:00:13 +00:00
static bool disableShaderCache = true ;
2024-01-16 09:50:41 +00:00
# if defined(QT_GUI_LIB)
2023-02-02 12:50:19 +00:00
static bool requestAlphaChannel = false ;
static bool requestMSAA = false ;
static bool requestCoreProfile = false ;
2024-01-16 09:50:41 +00:00
# endif
2012-12-21 23:42:47 +00:00
static void loadConf ( const QString & override , bool quiet ) // Terminates app on failure
{
2019-04-24 19:05:32 +00:00
const QString defaultFileName = QLatin1String ( " default.qml " ) ;
2012-12-21 23:42:47 +00:00
QUrl settingsUrl ;
bool builtIn = false ; //just for keeping track of the warning
if ( override . isEmpty ( ) ) {
QFileInfo fi ;
2020-10-23 22:06:41 +00:00
fi . setFile ( QStandardPaths : : locate ( QStandardPaths : : AppDataLocation , defaultFileName ) ) ;
2012-12-21 23:42:47 +00:00
if ( fi . exists ( ) ) {
2022-02-25 14:49:34 +00:00
settingsUrl = QQmlImports : : urlFromLocalFileOrQrcOrUrl ( fi . absoluteFilePath ( ) ) ;
2012-12-21 23:42:47 +00:00
} else {
// ### If different built-in configs are needed per-platform, just apply QFileSelector to the qrc conf.qml path
2019-04-24 19:05:32 +00:00
fi . setFile ( confResourcePath + defaultFileName ) ;
2022-02-25 14:49:34 +00:00
settingsUrl = QQmlImports : : urlFromLocalFileOrQrcOrUrl ( fi . absoluteFilePath ( ) ) ;
2012-12-21 23:42:47 +00:00
builtIn = true ;
}
} else {
QFileInfo fi ;
2019-04-24 19:05:32 +00:00
fi . setFile ( confResourcePath + override + QLatin1String ( " .qml " ) ) ;
if ( fi . exists ( ) ) {
2022-02-25 14:49:34 +00:00
settingsUrl = QQmlImports : : urlFromLocalFileOrQrcOrUrl ( fi . absoluteFilePath ( ) ) ;
2019-04-24 19:05:32 +00:00
builtIn = true ;
} else {
2021-09-21 13:23:55 +00:00
fi . setFile ( QDir ( QStandardPaths : : locate ( QStandardPaths : : AppConfigLocation , override , QStandardPaths : : LocateDirectory ) ) , customConfFileName ) ;
if ( fi . exists ( ) )
2022-02-25 14:49:34 +00:00
settingsUrl = QQmlImports : : urlFromLocalFileOrQrcOrUrl ( fi . absoluteFilePath ( ) ) ;
2021-09-21 13:23:55 +00:00
else
fi . setFile ( override ) ;
2019-04-24 19:05:32 +00:00
if ( ! fi . exists ( ) ) {
printf ( " qml: Couldn't find required configuration file: %s \n " ,
qPrintable ( QDir : : toNativeSeparators ( fi . absoluteFilePath ( ) ) ) ) ;
exit ( 1 ) ;
}
2022-02-25 14:49:34 +00:00
settingsUrl = QQmlImports : : urlFromLocalFileOrQrcOrUrl ( fi . absoluteFilePath ( ) ) ;
2012-12-21 23:42:47 +00:00
}
}
if ( ! quiet ) {
2015-06-03 09:05:12 +00:00
printf ( " qml: %s \n " , QLibraryInfo : : build ( ) ) ;
2019-04-24 19:05:32 +00:00
if ( builtIn ) {
printf ( " qml: Using built-in configuration: %s \n " ,
qPrintable ( override . isEmpty ( ) ? defaultFileName : override ) ) ;
} else {
printf ( " qml: Using configuration: %s \n " ,
2013-10-23 22:37:16 +00:00
qPrintable ( settingsUrl . isLocalFile ( )
? QDir : : toNativeSeparators ( settingsUrl . toLocalFile ( ) )
: settingsUrl . toString ( ) ) ) ;
2019-04-24 19:05:32 +00:00
}
2012-12-21 23:42:47 +00:00
}
// TODO: When we have better engine control, ban QtQuick* imports on this engine
QQmlEngine e2 ;
QQmlComponent c2 ( & e2 , settingsUrl ) ;
conf = qobject_cast < Config * > ( c2 . create ( ) ) ;
if ( ! conf ) {
2013-10-23 22:37:16 +00:00
printf ( " qml: Error loading configuration file: %s \n " , qPrintable ( c2 . errorString ( ) ) ) ;
2012-12-21 23:42:47 +00:00
exit ( 1 ) ;
}
}
2019-04-23 13:31:15 +00:00
void noFilesGiven ( )
{
if ( ! quietMode )
printf ( " qml: No files specified. Terminating. \n " ) ;
exit ( 1 ) ;
}
2013-10-12 02:59:09 +00:00
2019-04-24 19:05:32 +00:00
static void listConfFiles ( )
{
2021-09-21 13:23:55 +00:00
const QDir confResourceDir ( confResourcePath ) ;
2019-04-24 19:05:32 +00:00
printf ( " %s \n " , qPrintable ( QCoreApplication : : translate ( " main " , " Built-in configurations: " ) ) ) ;
2023-04-26 13:15:37 +00:00
for ( const QFileInfo & fi : confResourceDir . entryInfoList ( QDir : : Files ) ) {
if ( fi . completeSuffix ( ) ! = QLatin1String ( " qml " ) )
continue ;
const QString baseName = fi . baseName ( ) ;
if ( baseName . isEmpty ( ) | | baseName [ 0 ] . isUpper ( ) )
continue ;
printf ( " %s \n " , qPrintable ( baseName ) ) ;
}
2021-09-21 13:23:55 +00:00
printf ( " %s \n " , qPrintable ( QCoreApplication : : translate ( " main " , " Other configurations: " ) ) ) ;
bool foundOther = false ;
const QStringList otherLocations = QStandardPaths : : standardLocations ( QStandardPaths : : AppConfigLocation ) ;
for ( const auto & confDirPath : otherLocations ) {
const QDir confDir ( confDirPath ) ;
for ( const QFileInfo & fi : confDir . entryInfoList ( QDir : : Dirs | QDir : : NoDotAndDotDot ) ) {
foundOther = true ;
if ( verboseMode )
printf ( " %s \n " , qPrintable ( fi . absoluteFilePath ( ) ) ) ;
else
printf ( " %s \n " , qPrintable ( fi . baseName ( ) ) ) ;
}
}
if ( ! foundOther )
printf ( " %s \n " , qPrintable ( QCoreApplication : : translate ( " main " , " none " ) ) ) ;
if ( verboseMode ) {
printf ( " %s \n " , qPrintable ( QCoreApplication : : translate ( " main " , " Checked in: " ) ) ) ;
for ( const auto & confDirPath : otherLocations )
printf ( " %s \n " , qPrintable ( confDirPath ) ) ;
}
2019-04-24 19:05:32 +00:00
exit ( 0 ) ;
}
2019-04-23 13:31:15 +00:00
# ifdef QT_GUI_LIB
2013-11-18 14:57:08 +00:00
2012-12-21 23:42:47 +00:00
// Loads qml after receiving a QFileOpenEvent
class LoaderApplication : public QGuiApplication
{
public :
2019-04-15 13:59:03 +00:00
LoaderApplication ( int & argc , char * * argv ) : QGuiApplication ( argc , argv )
{
setWindowIcon ( QIcon ( iconResourcePath ) ) ;
}
2012-12-21 23:42:47 +00:00
2016-12-07 22:53:14 +00:00
bool event ( QEvent * ev ) override
2012-12-21 23:42:47 +00:00
{
2013-11-18 14:57:08 +00:00
if ( ev - > type ( ) = = QEvent : : FileOpen ) {
if ( exitTimerId > = 0 ) {
killTimer ( exitTimerId ) ;
exitTimerId = - 1 ;
}
2012-12-21 23:42:47 +00:00
qae - > load ( static_cast < QFileOpenEvent * > ( ev ) - > url ( ) ) ;
2013-11-18 14:57:08 +00:00
}
2012-12-21 23:42:47 +00:00
else
return QGuiApplication : : event ( ev ) ;
return true ;
}
2013-11-18 14:57:08 +00:00
2016-12-07 22:53:14 +00:00
void timerEvent ( QTimerEvent * ) override {
2013-11-18 14:57:08 +00:00
noFilesGiven ( ) ;
}
2012-12-21 23:42:47 +00:00
} ;
2013-10-12 02:59:09 +00:00
# endif // QT_GUI_LIB
2012-12-21 23:42:47 +00:00
// Listens to the appEngine signals to determine if all files failed to load
class LoadWatcher : public QObject
{
Q_OBJECT
public :
LoadWatcher ( QQmlApplicationEngine * e , int expected )
: QObject ( e )
2019-01-14 08:42:29 +00:00
, expectedFileCount ( expected )
2012-12-21 23:42:47 +00:00
{
2019-01-14 08:42:29 +00:00
connect ( e , & QQmlApplicationEngine : : objectCreated , this , & LoadWatcher : : checkFinished ) ;
2015-03-11 05:25:14 +00:00
// QQmlApplicationEngine also connects quit() to QCoreApplication::quit
2016-08-03 14:54:26 +00:00
// and exit() to QCoreApplication::exit but if called before exec()
// then QCoreApplication::quit or QCoreApplication::exit does nothing
2019-01-14 08:42:29 +00:00
connect ( e , & QQmlEngine : : quit , this , & LoadWatcher : : quit ) ;
connect ( e , & QQmlEngine : : exit , this , & LoadWatcher : : exit ) ;
2012-12-21 23:42:47 +00:00
}
2019-01-14 08:42:29 +00:00
int returnCode = 0 ;
2019-04-23 13:31:15 +00:00
bool earlyExit = false ;
2012-12-21 23:42:47 +00:00
public Q_SLOTS :
2019-01-14 08:42:29 +00:00
void checkFinished ( QObject * o , const QUrl & url )
2012-12-21 23:42:47 +00:00
{
2020-06-26 12:43:02 +00:00
Q_UNUSED ( url ) ;
2012-12-21 23:42:47 +00:00
if ( o ) {
2023-01-17 14:34:36 +00:00
+ + createdObjects ;
2012-12-21 23:42:47 +00:00
if ( conf & & qae )
2022-10-06 09:30:50 +00:00
for ( PartialScene * ps : std : : as_const ( conf - > completers ) )
2012-12-21 23:42:47 +00:00
if ( o - > inherits ( ps - > itemType ( ) . toUtf8 ( ) . constData ( ) ) )
contain ( o , ps - > container ( ) ) ;
}
2023-01-17 14:34:36 +00:00
if ( ! - - expectedFileCount & & ! createdObjects ) {
2013-10-23 22:37:16 +00:00
printf ( " qml: Did not load any objects, exiting. \n " ) ;
2021-07-08 12:32:44 +00:00
exit ( 2 ) ;
QCoreApplication : : exit ( 2 ) ;
2012-12-21 23:42:47 +00:00
}
}
2015-03-11 05:25:14 +00:00
void quit ( ) {
2019-01-14 08:42:29 +00:00
// Will be checked before calling exec()
2015-03-11 05:25:14 +00:00
earlyExit = true ;
2016-08-03 14:54:26 +00:00
returnCode = 0 ;
2015-03-11 05:25:14 +00:00
}
2016-08-03 14:54:26 +00:00
void exit ( int retCode ) {
earlyExit = true ;
returnCode = retCode ;
}
2019-01-14 08:42:29 +00:00
private :
void contain ( QObject * o , const QUrl & containPath ) ;
private :
2019-04-23 13:31:15 +00:00
int expectedFileCount ;
2023-01-17 14:34:36 +00:00
int createdObjects = 0 ;
2012-12-21 23:42:47 +00:00
} ;
2015-06-03 09:05:12 +00:00
void LoadWatcher : : contain ( QObject * o , const QUrl & containPath )
{
QQmlComponent c ( qae , containPath ) ;
QObject * o2 = c . create ( ) ;
if ( ! o2 )
return ;
2021-05-20 15:07:33 +00:00
o2 - > setParent ( this ) ;
2015-06-03 09:05:12 +00:00
bool success = false ;
int idx ;
if ( ( idx = o2 - > metaObject ( ) - > indexOfProperty ( " containedObject " ) ) ! = - 1 )
success = o2 - > metaObject ( ) - > property ( idx ) . write ( o2 , QVariant : : fromValue < QObject * > ( o ) ) ;
if ( ! success )
2019-01-14 08:42:29 +00:00
o - > setParent ( o2 ) ; // Set QObject parent, and assume container will react as needed
2015-06-03 09:05:12 +00:00
}
2012-12-21 23:42:47 +00:00
void quietMessageHandler ( QtMsgType type , const QMessageLogContext & ctxt , const QString & msg )
{
Q_UNUSED ( ctxt ) ;
Q_UNUSED ( msg ) ;
2019-01-14 08:42:29 +00:00
// Doesn't print anything
2012-12-21 23:42:47 +00:00
switch ( type ) {
case QtFatalMsg :
2013-09-25 16:11:34 +00:00
exit ( - 1 ) ;
2012-12-21 23:42:47 +00:00
case QtCriticalMsg :
case QtDebugMsg :
2019-04-23 13:20:15 +00:00
case QtInfoMsg :
2012-12-21 23:42:47 +00:00
case QtWarningMsg :
;
}
}
2020-01-15 09:55:27 +00:00
// Called before application initialization
static void getAppFlags ( int argc , char * * argv )
2012-12-21 23:42:47 +00:00
{
2013-10-12 02:59:09 +00:00
# ifdef QT_GUI_LIB
2013-11-14 11:38:25 +00:00
for ( int i = 0 ; i < argc ; i + + ) {
2019-04-16 15:25:36 +00:00
if ( ! strcmp ( argv [ i ] , " --apptype " ) | | ! strcmp ( argv [ i ] , " -a " ) | | ! strcmp ( argv [ i ] , " -apptype " ) ) {
2013-10-12 02:59:09 +00:00
applicationType = QmlApplicationTypeUnknown ;
2012-12-21 23:42:47 +00:00
if ( i + 1 < argc ) {
2020-01-15 09:55:27 +00:00
+ + i ;
if ( ! strcmp ( argv [ i ] , " core " ) )
2013-10-12 02:59:09 +00:00
applicationType = QmlApplicationTypeCore ;
2020-01-15 09:55:27 +00:00
else if ( ! strcmp ( argv [ i ] , " gui " ) )
2013-10-12 02:59:09 +00:00
applicationType = QmlApplicationTypeGui ;
2020-01-15 09:55:27 +00:00
# ifdef QT_WIDGETS_LIB
else if ( ! strcmp ( argv [ i ] , " widget " ) )
2013-10-12 02:59:09 +00:00
applicationType = QmlApplicationTypeWidget ;
2020-01-15 09:55:27 +00:00
# endif // QT_WIDGETS_LIB
2012-12-21 23:42:47 +00:00
}
2020-01-15 09:55:27 +00:00
} else if ( ! strcmp ( argv [ i ] , " -desktop " ) | | ! strcmp ( argv [ i ] , " --desktop " ) ) {
QCoreApplication : : setAttribute ( Qt : : AA_UseDesktopOpenGL ) ;
} else if ( ! strcmp ( argv [ i ] , " -gles " ) | | ! strcmp ( argv [ i ] , " --gles " ) ) {
QCoreApplication : : setAttribute ( Qt : : AA_UseOpenGLES ) ;
} else if ( ! strcmp ( argv [ i ] , " -software " ) | | ! strcmp ( argv [ i ] , " --software " ) ) {
QCoreApplication : : setAttribute ( Qt : : AA_UseSoftwareOpenGL ) ;
2021-03-18 14:10:46 +00:00
} else if ( ! strcmp ( argv [ i ] , " -disable-context-sharing " ) | | ! strcmp ( argv [ i ] , " --disable-context-sharing " ) ) {
glShareContexts = false ;
2023-02-02 10:00:13 +00:00
} else if ( ! strcmp ( argv [ i ] , " -enable-shader-cache " ) | | ! strcmp ( argv [ i ] , " --enable-shader-cache " ) ) {
disableShaderCache = false ;
2023-02-02 12:50:19 +00:00
} else if ( ! strcmp ( argv [ i ] , " -transparent " ) | | ! strcmp ( argv [ i ] , " --transparent " ) ) {
requestAlphaChannel = true ;
} else if ( ! strcmp ( argv [ i ] , " -multisample " ) | | ! strcmp ( argv [ i ] , " --multisample " ) ) {
requestMSAA = true ;
} else if ( ! strcmp ( argv [ i ] , " -core-profile " ) | | ! strcmp ( argv [ i ] , " --core-profile " ) ) {
requestCoreProfile = true ;
2012-12-21 23:42:47 +00:00
}
}
2017-04-12 13:45:18 +00:00
# else
2020-06-26 12:43:02 +00:00
Q_UNUSED ( argc ) ;
Q_UNUSED ( argv ) ;
2013-11-14 11:38:25 +00:00
# endif // QT_GUI_LIB
2012-12-21 23:42:47 +00:00
}
2021-09-22 18:33:51 +00:00
# if QT_DEPRECATED_SINCE(6, 3)
2012-12-21 23:42:47 +00:00
static void loadDummyDataFiles ( QQmlEngine & engine , const QString & directory )
{
QDir dir ( directory + " /dummydata " , " *.qml " ) ;
QStringList list = dir . entryList ( ) ;
for ( int i = 0 ; i < list . size ( ) ; + + i ) {
QString qml = list . at ( i ) ;
2014-03-01 06:28:29 +00:00
QQmlComponent comp ( & engine , dir . filePath ( qml ) ) ;
2012-12-21 23:42:47 +00:00
QObject * dummyData = comp . create ( ) ;
if ( comp . isError ( ) ) {
2016-08-11 10:08:00 +00:00
const QList < QQmlError > errors = comp . errors ( ) ;
for ( const QQmlError & error : errors )
2012-12-21 23:42:47 +00:00
qWarning ( ) < < error ;
}
if ( dummyData & & ! quietMode ) {
2013-10-23 22:37:16 +00:00
printf ( " qml: Loaded dummy data: %s \n " , qPrintable ( dir . filePath ( qml ) ) ) ;
2022-10-05 05:29:16 +00:00
qml . truncate ( qml . size ( ) - 4 ) ;
2012-12-21 23:42:47 +00:00
engine . rootContext ( ) - > setContextProperty ( qml , dummyData ) ;
dummyData - > setParent ( & engine ) ;
}
}
}
2021-09-22 18:33:51 +00:00
# endif
2012-12-21 23:42:47 +00:00
int main ( int argc , char * argv [ ] )
{
getAppFlags ( argc , argv ) ;
2021-03-18 14:10:46 +00:00
2023-02-02 12:50:19 +00:00
// Must set the default QSurfaceFormat before creating the app object if
// AA_ShareOpenGLContexts is going to be set.
# if defined(QT_GUI_LIB)
QSurfaceFormat surfaceFormat ;
surfaceFormat . setDepthBufferSize ( 24 ) ;
surfaceFormat . setStencilBufferSize ( 8 ) ;
if ( requestMSAA )
surfaceFormat . setSamples ( 4 ) ;
2023-03-16 15:21:37 +00:00
if ( requestAlphaChannel )
2023-02-02 12:50:19 +00:00
surfaceFormat . setAlphaBufferSize ( 8 ) ;
if ( qEnvironmentVariableIsSet ( " QSG_CORE_PROFILE " )
| | qEnvironmentVariableIsSet ( " QML_CORE_PROFILE " )
| | requestCoreProfile )
{
// intentionally requesting 4.1 core to play nice with macOS
surfaceFormat . setVersion ( 4 , 1 ) ;
surfaceFormat . setProfile ( QSurfaceFormat : : CoreProfile ) ;
}
QSurfaceFormat : : setDefaultFormat ( surfaceFormat ) ;
# endif
2021-03-18 14:10:46 +00:00
if ( glShareContexts )
QCoreApplication : : setAttribute ( Qt : : AA_ShareOpenGLContexts ) ;
2023-02-02 10:00:13 +00:00
if ( disableShaderCache )
QCoreApplication : : setAttribute ( Qt : : AA_DisableShaderDiskCache ) ;
2021-03-18 14:10:46 +00:00
2019-09-30 08:53:49 +00:00
std : : unique_ptr < QCoreApplication > app ;
2013-10-12 02:59:09 +00:00
switch ( applicationType ) {
# ifdef QT_GUI_LIB
case QmlApplicationTypeGui :
2020-11-17 12:41:35 +00:00
app = std : : make_unique < LoaderApplication > ( argc , argv ) ;
2013-10-12 02:59:09 +00:00
break ;
2012-12-21 23:42:47 +00:00
# ifdef QT_WIDGETS_LIB
2013-10-12 02:59:09 +00:00
case QmlApplicationTypeWidget :
2020-11-17 12:41:35 +00:00
app = std : : make_unique < QApplication > ( argc , argv ) ;
2019-09-30 08:53:49 +00:00
static_cast < QApplication * > ( app . get ( ) ) - > setWindowIcon ( QIcon ( iconResourcePath ) ) ;
2013-10-12 02:59:09 +00:00
break ;
# endif // QT_WIDGETS_LIB
# endif // QT_GUI_LIB
2019-04-16 15:25:36 +00:00
case QmlApplicationTypeCore :
Q_FALLTHROUGH ( ) ;
default : // QmlApplicationTypeUnknown: not allowed, but we'll exit after checking apptypeOption below
2020-11-17 12:41:35 +00:00
app = std : : make_unique < QCoreApplication > ( argc , argv ) ;
2013-10-12 02:59:09 +00:00
break ;
}
2012-12-21 23:42:47 +00:00
app - > setApplicationName ( " Qml Runtime " ) ;
2014-06-27 10:59:14 +00:00
app - > setOrganizationName ( " QtProject " ) ;
2012-12-21 23:42:47 +00:00
app - > setOrganizationDomain ( " qt-project.org " ) ;
2016-11-08 12:09:54 +00:00
QCoreApplication : : setApplicationVersion ( QLatin1String ( QT_VERSION_STR ) ) ;
2012-12-21 23:42:47 +00:00
QStringList files ;
QString confFile ;
QString translationFile ;
2019-01-14 08:42:29 +00:00
// Handle main arguments
2019-04-16 15:25:36 +00:00
QCommandLineParser parser ;
parser . setSingleDashWordOptionMode ( QCommandLineParser : : ParseAsLongOptions ) ;
parser . setOptionsAfterPositionalArgumentsMode ( QCommandLineParser : : ParseAsPositionalArguments ) ;
2023-05-16 05:59:46 +00:00
parser . addHelpOption ( ) ;
parser . addVersionOption ( ) ;
2019-04-16 15:25:36 +00:00
# ifdef QT_GUI_LIB
QCommandLineOption apptypeOption ( QStringList ( ) < < QStringLiteral ( " a " ) < < QStringLiteral ( " apptype " ) ,
QCoreApplication : : translate ( " main " , " Select which application class to use. Default is gui. " ) ,
# ifdef QT_WIDGETS_LIB
QStringLiteral ( " core|gui|widget " ) ) ;
# else
QStringLiteral ( " core|gui " ) ) ;
# endif // QT_WIDGETS_LIB
parser . addOption ( apptypeOption ) ; // Just for the help text... we've already handled this argument above
# endif // QT_GUI_LIB
QCommandLineOption importOption ( QStringLiteral ( " I " ) ,
QCoreApplication : : translate ( " main " , " Prepend the given path to the import paths. " ) , QStringLiteral ( " path " ) ) ;
parser . addOption ( importOption ) ;
QCommandLineOption qmlFileOption ( QStringLiteral ( " f " ) ,
QCoreApplication : : translate ( " main " , " Load the given file as a QML file. " ) , QStringLiteral ( " file " ) ) ;
parser . addOption ( qmlFileOption ) ;
QCommandLineOption configOption ( QStringList ( ) < < QStringLiteral ( " c " ) < < QStringLiteral ( " config " ) ,
2019-04-24 19:05:32 +00:00
QCoreApplication : : translate ( " main " , " Load the given built-in configuration or configuration file. " ) , QStringLiteral ( " file " ) ) ;
2019-04-16 15:25:36 +00:00
parser . addOption ( configOption ) ;
2019-04-24 19:05:32 +00:00
QCommandLineOption listConfOption ( QStringList ( ) < < QStringLiteral ( " list-conf " ) ,
QCoreApplication : : translate ( " main " , " List the built-in configurations. " ) ) ;
parser . addOption ( listConfOption ) ;
2019-04-16 15:25:36 +00:00
QCommandLineOption translationOption ( QStringLiteral ( " translation " ) ,
QCoreApplication : : translate ( " main " , " Load the given file as the translations file. " ) , QStringLiteral ( " file " ) ) ;
parser . addOption ( translationOption ) ;
2021-09-22 18:33:51 +00:00
# if QT_DEPRECATED_SINCE(6, 3)
2019-04-16 15:25:36 +00:00
QCommandLineOption dummyDataOption ( QStringLiteral ( " dummy-data " ) ,
2021-09-22 18:33:51 +00:00
QCoreApplication : : translate ( " main " , " Load QML files from the given directory as context properties. (deprecated) " ) , QStringLiteral ( " file " ) ) ;
2019-04-16 15:25:36 +00:00
parser . addOption ( dummyDataOption ) ;
2021-09-22 18:33:51 +00:00
# endif
2020-01-15 09:55:27 +00:00
# ifdef QT_GUI_LIB
2019-04-16 15:25:36 +00:00
// OpenGL options
QCommandLineOption glDesktopOption ( QStringLiteral ( " desktop " ) ,
QCoreApplication : : translate ( " main " , " Force use of desktop OpenGL (AA_UseDesktopOpenGL). " ) ) ;
2020-01-15 09:55:27 +00:00
parser . addOption ( glDesktopOption ) ; // Just for the help text... we've already handled this argument above
2019-04-16 15:25:36 +00:00
QCommandLineOption glEsOption ( QStringLiteral ( " gles " ) ,
QCoreApplication : : translate ( " main " , " Force use of GLES (AA_UseOpenGLES). " ) ) ;
2020-01-15 09:55:27 +00:00
parser . addOption ( glEsOption ) ; // Just for the help text... we've already handled this argument above
2019-04-16 15:25:36 +00:00
QCommandLineOption glSoftwareOption ( QStringLiteral ( " software " ) ,
QCoreApplication : : translate ( " main " , " Force use of software rendering (AA_UseSoftwareOpenGL). " ) ) ;
2020-01-15 09:55:27 +00:00
parser . addOption ( glSoftwareOption ) ; // Just for the help text... we've already handled this argument above
2021-03-16 09:40:54 +00:00
QCommandLineOption glCoreProfile ( QStringLiteral ( " core-profile " ) ,
QCoreApplication : : translate ( " main " , " Force use of OpenGL Core Profile. " ) ) ;
2023-02-02 12:50:19 +00:00
parser . addOption ( glCoreProfile ) ; // Just for the help text... we've already handled this argument above
2021-03-18 14:10:46 +00:00
QCommandLineOption glContextSharing ( QStringLiteral ( " disable-context-sharing " ) ,
QCoreApplication : : translate ( " main " , " Disable the use of a shared GL context for QtQuick Windows " ) ) ;
parser . addOption ( glContextSharing ) ; // Just for the help text... we've already handled this argument above
2023-02-02 12:50:19 +00:00
// Options relevant for other 3D APIs as well
2023-02-02 10:00:13 +00:00
QCommandLineOption shaderCaching ( QStringLiteral ( " enable-shader-cache " ) ,
QCoreApplication : : translate ( " main " , " Enable persistent caching of generated shaders " ) ) ;
parser . addOption ( shaderCaching ) ; // Just for the help text... we've already handled this argument above
2023-02-02 12:50:19 +00:00
QCommandLineOption transparentOption ( QStringLiteral ( " transparent " ) ,
QCoreApplication : : translate ( " main " , " Requests an alpha channel in order to enable semi-transparent windows. " ) ) ;
parser . addOption ( transparentOption ) ; // Just for the help text... we've already handled this argument above
QCommandLineOption multisampleOption ( QStringLiteral ( " multisample " ) ,
QCoreApplication : : translate ( " main " , " Requests 4x multisample antialiasing. " ) ) ;
parser . addOption ( multisampleOption ) ; // Just for the help text... we've already handled this argument above
2020-01-15 09:55:27 +00:00
# endif // QT_GUI_LIB
2023-02-02 12:50:19 +00:00
2019-04-16 15:25:36 +00:00
// Debugging and verbosity options
QCommandLineOption quietOption ( QStringLiteral ( " quiet " ) ,
QCoreApplication : : translate ( " main " , " Suppress all output. " ) ) ;
parser . addOption ( quietOption ) ;
QCommandLineOption verboseOption ( QStringLiteral ( " verbose " ) ,
QCoreApplication : : translate ( " main " , " Print information about what qml is doing, like specific file URLs being loaded. " ) ) ;
parser . addOption ( verboseOption ) ;
QCommandLineOption slowAnimationsOption ( QStringLiteral ( " slow-animations " ) ,
QCoreApplication : : translate ( " main " , " Run all animations in slow motion. " ) ) ;
parser . addOption ( slowAnimationsOption ) ;
QCommandLineOption fixedAnimationsOption ( QStringLiteral ( " fixed-animations " ) ,
QCoreApplication : : translate ( " main " , " Run animations off animation tick rather than wall time. " ) ) ;
parser . addOption ( fixedAnimationsOption ) ;
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
QCommandLineOption rhiOption ( QStringList ( ) < < QStringLiteral ( " r " ) < < QStringLiteral ( " rhi " ) ,
2020-06-16 15:03:47 +00:00
QCoreApplication : : translate ( " main " , " Set the backend for the Qt graphics abstraction (RHI). "
2024-03-08 08:37:39 +00:00
" Backend is one of: default, vulkan, metal, d3d11, d3d12, opengl " ) ,
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
QStringLiteral ( " backend " ) ) ;
parser . addOption ( rhiOption ) ;
2020-01-30 14:43:57 +00:00
QCommandLineOption selectorOption ( QStringLiteral ( " S " ) , QCoreApplication : : translate ( " main " ,
" Add selector to the list of QQmlFileSelectors. " ) , QStringLiteral ( " selector " ) ) ;
parser . addOption ( selectorOption ) ;
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
2019-04-16 15:25:36 +00:00
// Positional arguments
parser . addPositionalArgument ( " files " ,
QCoreApplication : : translate ( " main " , " Any number of QML files can be loaded. They will share the same engine. " ) , " [files...] " ) ;
parser . addPositionalArgument ( " args " ,
QCoreApplication : : translate ( " main " , " Arguments after '--' are ignored, but passed through to the application.arguments variable in QML. " ) , " [-- args...] " ) ;
2023-05-16 05:59:46 +00:00
parser . process ( * app ) ;
2021-09-21 13:23:55 +00:00
if ( parser . isSet ( verboseOption ) )
verboseMode = true ;
if ( parser . isSet ( quietOption ) ) {
quietMode = true ;
verboseMode = false ;
}
2019-04-24 19:05:32 +00:00
if ( parser . isSet ( listConfOption ) )
listConfFiles ( ) ;
2019-04-16 15:25:36 +00:00
if ( applicationType = = QmlApplicationTypeUnknown ) {
# ifdef QT_WIDGETS_LIB
qWarning ( ) < < QCoreApplication : : translate ( " main " , " --apptype must be followed by one of the following: core gui widget \n " ) ;
# else
qWarning ( ) < < QCoreApplication : : translate ( " main " , " --apptype must be followed by one of the following: core gui \n " ) ;
# endif // QT_WIDGETS_LIB
parser . showHelp ( ) ;
}
2017-12-19 15:37:24 +00:00
# if QT_CONFIG(qml_animation)
2019-04-16 15:25:36 +00:00
if ( parser . isSet ( slowAnimationsOption ) )
QUnifiedTimer : : instance ( ) - > setSlowModeEnabled ( true ) ;
if ( parser . isSet ( fixedAnimationsOption ) )
QUnifiedTimer : : instance ( ) - > setConsistentTiming ( true ) ;
2017-03-30 08:41:52 +00:00
# endif
2023-04-26 13:26:36 +00:00
QQmlApplicationEngine e ;
2019-04-16 15:25:36 +00:00
for ( const QString & importPath : parser . values ( importOption ) )
e . addImportPath ( importPath ) ;
2020-01-30 14:43:57 +00:00
QStringList customSelectors ;
for ( const QString & selector : parser . values ( selectorOption ) )
customSelectors . append ( selector ) ;
2020-02-07 15:59:51 +00:00
if ( ! customSelectors . isEmpty ( ) )
e . setExtraFileSelectors ( customSelectors ) ;
2020-01-30 14:43:57 +00:00
2019-04-16 15:25:36 +00:00
files < < parser . values ( qmlFileOption ) ;
if ( parser . isSet ( configOption ) )
confFile = parser . value ( configOption ) ;
if ( parser . isSet ( translationOption ) )
translationFile = parser . value ( translationOption ) ;
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
if ( parser . isSet ( rhiOption ) ) {
const QString rhiBackend = parser . value ( rhiOption ) ;
if ( rhiBackend = = QLatin1String ( " default " ) )
qunsetenv ( " QSG_RHI_BACKEND " ) ;
else
qputenv ( " QSG_RHI_BACKEND " , rhiBackend . toLatin1 ( ) ) ;
}
2019-04-16 15:25:36 +00:00
for ( QString posArg : parser . positionalArguments ( ) ) {
if ( posArg = = QLatin1String ( " -- " ) )
break ;
else
files < < posArg ;
2012-12-21 23:42:47 +00:00
}
2016-11-16 13:22:36 +00:00
# if QT_CONFIG(translation)
2018-06-28 14:47:11 +00:00
// Need to be installed before QQmlApplicationEngine's automatic translation loading
// (qt_ translations are loaded there)
2023-02-08 12:19:53 +00:00
QTranslator translator ;
2018-06-28 14:47:11 +00:00
if ( ! translationFile . isEmpty ( ) ) {
2012-12-21 23:42:47 +00:00
if ( translator . load ( translationFile ) ) {
app - > installTranslator ( & translator ) ;
2013-10-23 22:37:16 +00:00
if ( verboseMode )
printf ( " qml: Loaded translation file %s \n " , qPrintable ( QDir : : toNativeSeparators ( translationFile ) ) ) ;
2012-12-21 23:42:47 +00:00
} else {
if ( ! quietMode )
2013-10-23 22:37:16 +00:00
printf ( " qml: Could not load the translation file %s \n " , qPrintable ( QDir : : toNativeSeparators ( translationFile ) ) ) ;
2012-12-21 23:42:47 +00:00
}
}
# else
if ( ! translationFile . isEmpty ( ) & & ! quietMode )
2013-10-23 22:37:16 +00:00
printf ( " qml: Translation file specified, but Qt built without translation support. \n " ) ;
2012-12-21 23:42:47 +00:00
# endif
2019-04-23 13:20:15 +00:00
if ( quietMode ) {
2012-12-21 23:42:47 +00:00
qInstallMessageHandler ( quietMessageHandler ) ;
2019-04-23 13:20:15 +00:00
QLoggingCategory : : setFilterRules ( QStringLiteral ( " *=false " ) ) ;
}
2012-12-21 23:42:47 +00:00
2022-10-05 05:29:16 +00:00
if ( files . size ( ) < = 0 ) {
2019-12-22 13:57:14 +00:00
# if defined(Q_OS_DARWIN) && defined(QT_GUI_LIB)
2013-11-18 14:57:08 +00:00
if ( applicationType = = QmlApplicationTypeGui )
2019-09-30 08:53:49 +00:00
exitTimerId = static_cast < LoaderApplication * > ( app . get ( ) ) - > startTimer ( FILE_OPEN_EVENT_WAIT_TIME ) ;
2013-11-18 14:57:08 +00:00
else
# endif
noFilesGiven ( ) ;
2012-12-21 23:42:47 +00:00
}
qae = & e ;
2013-10-23 22:37:16 +00:00
loadConf ( confFile , ! verboseMode ) ;
2012-12-21 23:42:47 +00:00
2019-01-14 08:42:29 +00:00
// Load files
2022-10-05 05:29:16 +00:00
QScopedPointer < LoadWatcher > lw ( new LoadWatcher ( & e , files . size ( ) ) ) ;
2012-12-21 23:42:47 +00:00
2021-09-22 18:33:51 +00:00
# if QT_DEPRECATED_SINCE(6, 3)
QString dummyDir ;
if ( parser . isSet ( dummyDataOption ) )
dummyDir = parser . value ( dummyDataOption ) ;
2014-03-01 06:28:29 +00:00
// Load dummy data before loading QML-files
2021-09-22 18:33:51 +00:00
if ( ! dummyDir . isEmpty ( ) & & QFileInfo ( dummyDir ) . isDir ( ) ) {
qCWarning ( lcDeprecated ( ) ) < < " Warning: the qml --dummy-data option is deprecated and will be removed in a future version of Qt. " ;
2014-03-01 06:28:29 +00:00
loadDummyDataFiles ( e , dummyDir ) ;
2021-09-22 18:33:51 +00:00
}
# endif
2014-03-01 06:28:29 +00:00
2022-10-06 09:30:50 +00:00
for ( const QString & path : std : : as_const ( files ) ) {
2017-03-15 10:16:20 +00:00
QUrl url = QUrl : : fromUserInput ( path , QDir : : currentPath ( ) , QUrl : : AssumeLocalFile ) ;
2017-01-02 13:04:48 +00:00
if ( verboseMode )
printf ( " qml: loading %s \n " , qPrintable ( url . toString ( ) ) ) ;
Uniformly support shebang
The "qml" tool was the only way of loading QML files that would respect
a shebang line. This is problematic as this way you cannot load such
files programatically using QQmlComponent, limiting their re-use. Common
tools like Qt Creator, but also qmllint, qmlformat, qmlcachegen, etc
would not recognize files with shebangs.
By moving she-bang support directly in the lexer all tools implicitly
support it.
Note that we could just as easily support '#' as extra comment
character along with //, but here we narrowly add support for in
the first line only, as node does (this means that javascript files
using she-bang accepted by node, are now accepted also by qml).
The only tool needing some adjustments is qmlformat, that has to emit
the she-bang again as she-bang and as first line.
Add tests for qmlformat, and sprinkle some she-bangs in the other
tests just to be sure it doesn't affect anything.
Change-Id: I1f6d881c7438bdb23163b5dbe829d59a35d11132
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2021-02-03 08:06:09 +00:00
e . load ( url ) ;
2012-12-21 23:42:47 +00:00
}
2015-03-11 05:25:14 +00:00
if ( lw - > earlyExit )
2016-08-03 14:54:26 +00:00
return lw - > returnCode ;
2015-03-11 05:25:14 +00:00
2012-12-21 23:42:47 +00:00
return app - > exec ( ) ;
}
# include "main.moc"