DiscoverMainWindow::DiscoverMainWindow(CompactMode mode) : QObject() , m_collection(this) , m_engine(new QQmlApplicationEngine) , m_mode(mode) { ResourcesModel *m = ResourcesModel::global(); m->integrateActions(actionCollection()); setObjectName(QStringLiteral("DiscoverMain")); KDeclarative::KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(m_engine); kdeclarative.setupBindings(); qmlRegisterType<UnityLauncher>("org.kde.discover.app", 1, 0, "UnityLauncher"); qmlRegisterType<PaginateModel>("org.kde.discover.app", 1, 0, "PaginateModel"); qmlRegisterType<IconColors>("org.kde.discover.app", 1, 0, "IconColors"); qmlRegisterType<KConcatenateRowsProxyModel>("org.kde.discover.app", 1, 0, "KConcatenateRowsProxyModel"); qmlRegisterSingletonType<SystemFonts>("org.kde.discover.app", 1, 0, "SystemFonts", ([](QQmlEngine*, QJSEngine*) -> QObject* { return new SystemFonts; })); qmlRegisterSingletonType(QUrl(QStringLiteral("qrc:/qml/DiscoverSystemPalette.qml")), "org.kde.discover.app", 1, 0, "DiscoverSystemPalette"); qmlRegisterSingletonType(QUrl(QStringLiteral("qrc:/qml/Helpers.qml")), "org.kde.discover.app", 1, 0, "Helpers"); qmlRegisterType<QQuickView>(); qmlRegisterType<QActionGroup>(); qmlRegisterType<QAction>(); qmlRegisterUncreatableType<DiscoverMainWindow>("org.kde.discover.app", 1, 0, "DiscoverMainWindow", QStringLiteral("don't do that")); setupActions(); //Here we set up a cache for the screenshots m_engine->rootContext()->setContextProperty(QStringLiteral("app"), this); connect(m_engine, &QQmlApplicationEngine::objectCreated, this, &DiscoverMainWindow::integrateObject); m_engine->load(QUrl(QStringLiteral("qrc:/qml/DiscoverWindow.qml"))); }
int main(int argc, char *argv[]) { QGuiApplication::setApplicationName("BaasExample"); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; //#if defined(Q_OS_ANDROID) //TODO : fix registering via registerFilterTypes() Q_COREAPP_STARTUP_FUNCTION (not called with Android?) //registerFilterTypes(); //#endif qmlRegisterSingletonType( QUrl("qrc:/qml/singleton/Assets.qml"),"BaaS.Example.Assets", 1, 0,"Assets"); #ifdef APPVERSION engine.rootContext()->setContextProperty( "appVersion", QString( APPVERSION )); #endif engine.addImportPath("qrc:///"); engine.load(QUrl(QLatin1String("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }
void tst_qmldiskcache::cppRegisteredSingletonDependency() { qmlClearTypeRegistrations(); QScopedPointer<QQmlEngine> engine(new QQmlEngine); QTemporaryDir tempDir; QVERIFY(tempDir.isValid()); const auto writeTempFile = [&tempDir](const QString &fileName, const char *contents) { QFile f(tempDir.path() + '/' + fileName); const bool ok = f.open(QIODevice::WriteOnly | QIODevice::Truncate); Q_ASSERT(ok); f.write(contents); return f.fileName(); }; writeTempFile("MySingleton.qml", "import QtQml 2.0\npragma Singleton\nQtObject { property int value: 42 }"); qmlRegisterSingletonType(QUrl::fromLocalFile(tempDir.path() + QLatin1String("/MySingleton.qml")), "CppRegisteredSingletonDependency", 1, 0, "Singly"); const QString testFilePath = writeTempFile("main.qml", "import QtQml 2.0\nimport CppRegisteredSingletonDependency 1.0\nQtObject {\n" " function getValue() { return Singly.value; }\n" "}"); { CleanlyLoadingComponent component(engine.data(), QUrl::fromLocalFile(testFilePath)); QScopedPointer<QObject> obj(component.create()); QVERIFY(!obj.isNull()); QVariant value; QVERIFY(QMetaObject::invokeMethod(obj.data(), "getValue", Q_RETURN_ARG(QVariant, value))); QCOMPARE(value.toInt(), 42); } const QString testFileCachePath = testFilePath + QLatin1Char('c'); QVERIFY(QFile::exists(testFileCachePath)); QDateTime initialCacheTimeStamp = QFileInfo(testFileCachePath).lastModified(); engine.reset(new QQmlEngine); waitForFileSystem(); writeTempFile("MySingleton.qml", "import QtQml 2.0\npragma Singleton\nQtObject { property int value: 100 }"); waitForFileSystem(); { CleanlyLoadingComponent component(engine.data(), QUrl::fromLocalFile(testFilePath)); QScopedPointer<QObject> obj(component.create()); QVERIFY(!obj.isNull()); { QVERIFY(QFile::exists(testFileCachePath)); QDateTime newCacheTimeStamp = QFileInfo(testFileCachePath).lastModified(); QVERIFY2(newCacheTimeStamp > initialCacheTimeStamp, qPrintable(newCacheTimeStamp.toString())); } QVariant value; QVERIFY(QMetaObject::invokeMethod(obj.data(), "getValue", Q_RETURN_ARG(QVariant, value))); QCOMPARE(value.toInt(), 100); } }
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); app.setApplicationName("Ballade2"); app.setApplicationVersion("16.08"); qmlRegisterSingletonType<B2File>("B2.File", 1, 0, "File", &B2File::singleton); qmlRegisterSingletonType( QUrl(QStringLiteral("qrc:/B2Func.qml")), "B2.Func", 1, 0, "Func" ); qmlRegisterSingletonType( QUrl(QStringLiteral("qrc:/B2LabelFunc.qml")), "B2.LabelFunc", 1, 0, "LabelFunc" ); qmlRegisterSingletonType( QUrl(QStringLiteral("qrc:/B2Notification.qml")), "B2.Notification", 1, 0, "Notification" ); qmlRegisterSingletonType( QUrl(QStringLiteral("qrc:/B2Parser.qml")), "B2.Parser", 1, 0, "Parser" ); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
QAQmlTypes() { // QADevice is a exception. Won't register by QAQmlTypes. qmlRegisterSingletonType<QASystemDispatcherProxy>("QuickAndroid", 0, 1, "SystemDispatcher", systemDispatcherProvider); qmlRegisterType<QALine>("QuickAndroid.Private",0,1,"Line"); qmlRegisterType<QAMouseSensor>("QuickAndroid.Private",0,1,"MouseSensor"); qmlRegisterSingletonType("QuickAndroid.Private", 0, 1, "TimerUtils", timerProvider); qmlRegisterType<QAImageWriter>("QuickAndroid.Private",0,1,"ImageWriter"); }
void QtQuickExtrasStylesPlugin::registerTypes(const char *uri) { Q_INIT_RESOURCE(flatstyle); const QString prefix = "qrc:/ExtrasImports/QtQuick/Controls/Styles/Flat/"; // register version 1.0 qmlRegisterSingletonType(QUrl(prefix + "FlatStyle.qml"), uri, 1, 0, "FlatStyle"); qmlRegisterType(QUrl(prefix + "ApplicationWindowStyle.qml"), uri, 1, 0, "ApplicationWindowStyle"); qmlRegisterType(QUrl(prefix + "BusyIndicatorStyle.qml"), uri, 1, 0, "BusyIndicatorStyle"); qmlRegisterType(QUrl(prefix + "ButtonStyle.qml"), uri, 1, 0, "ButtonStyle"); qmlRegisterType(QUrl(prefix + "CalendarStyle.qml"), uri, 1, 0, "CalendarStyle"); qmlRegisterType(QUrl(prefix + "CheckBoxStyle.qml"), uri, 1, 0, "CheckBoxStyle"); qmlRegisterType(QUrl(prefix + "CheckBoxDrawer.qml"), uri, 1, 0, "CheckBoxDrawer"); qmlRegisterType(QUrl(prefix + "CircularButtonStyle.qml"), uri, 1, 0, "CircularButtonStyle"); qmlRegisterType(QUrl(prefix + "CircularGaugeStyle.qml"), uri, 1, 0, "CircularGaugeStyle"); qmlRegisterType(QUrl(prefix + "CircularTickmarkLabelStyle.qml"), uri, 1, 0, "CircularTickmarkLabelStyle"); qmlRegisterType(QUrl(prefix + "ComboBoxStyle.qml"), uri, 1, 0, "ComboBoxStyle"); qmlRegisterType(QUrl(prefix + "CursorHandleStyle.qml"), uri, 1, 0, "CursorHandleStyle"); qmlRegisterType(QUrl(prefix + "DelayButtonStyle.qml"), uri, 1, 0, "DelayButtonStyle"); qmlRegisterType(QUrl(prefix + "FocusFrameStyle.qml"), uri, 1, 0, "FocusFrameStyle"); qmlRegisterType(QUrl(prefix + "GaugeStyle.qml"), uri, 1, 0, "GaugeStyle"); qmlRegisterType(QUrl(prefix + "GroupBoxStyle.qml"), uri, 1, 0, "GroupBoxStyle"); qmlRegisterType(QUrl(prefix + "LeftArrowIcon.qml"), uri, 1, 0, "LeftArrowIcon"); qmlRegisterType(QUrl(prefix + "MenuBarStyle.qml"), uri, 1, 0, "MenuBarStyle"); qmlRegisterType(QUrl(prefix + "PieMenuStyle.qml"), uri, 1, 0, "PieMenuStyle"); qmlRegisterType(QUrl(prefix + "ProgressBarStyle.qml"), uri, 1, 0, "ProgressBarStyle"); qmlRegisterType(QUrl(prefix + "RadioButtonStyle.qml"), uri, 1, 0, "RadioButtonStyle"); qmlRegisterType(QUrl(prefix + "ScrollViewStyle.qml"), uri, 1, 0, "ScrollViewStyle"); qmlRegisterType(QUrl(prefix + "SelectionHandleStyle.qml"), uri, 1, 0, "SelectionHandleStyle"); qmlRegisterType(QUrl(prefix + "SliderStyle.qml"), uri, 1, 0, "SliderStyle"); qmlRegisterType(QUrl(prefix + "SpinBoxStyle.qml"), uri, 1, 0, "SpinBoxStyle"); qmlRegisterType(QUrl(prefix + "StatusBarStyle.qml"), uri, 1, 0, "StatusBarStyle"); qmlRegisterType(QUrl(prefix + "StatusIndicatorStyle.qml"), uri, 1, 0, "StatusIndicatorStyle"); qmlRegisterType(QUrl(prefix + "SwitchStyle.qml"), uri, 1, 0, "SwitchStyle"); qmlRegisterType(QUrl(prefix + "TabViewStyle.qml"), uri, 1, 0, "TabViewStyle"); qmlRegisterType(QUrl(prefix + "TableViewStyle.qml"), uri, 1, 0, "TableViewStyle"); qmlRegisterType(QUrl(prefix + "TextAreaStyle.qml"), uri, 1, 0, "TextAreaStyle"); qmlRegisterType(QUrl(prefix + "TextFieldStyle.qml"), uri, 1, 0, "TextFieldStyle"); qmlRegisterType(QUrl(prefix + "ToggleButtonStyle.qml"), uri, 1, 0, "ToggleButtonStyle"); qmlRegisterType(QUrl(prefix + "ToolBarStyle.qml"), uri, 1, 0, "ToolBarStyle"); qmlRegisterType(QUrl(prefix + "ToolButtonStyle.qml"), uri, 1, 0, "ToolButtonStyle"); qmlRegisterType(QUrl(prefix + "ToolButtonBackground.qml"), uri, 1, 0, "ToolButtonBackground"); qmlRegisterType(QUrl(prefix + "ToolButtonIndicator.qml"), uri, 1, 0, "ToolButtonIndicator"); qmlRegisterType(QUrl(prefix + "TumblerStyle.qml"), uri, 1, 0, "TumblerStyle"); qmlRegisterType<QQuickTextHandle>("QtQuick.Controls.Styles.Flat", 1, 0, "TextHandle"); }
int main( int argc, char *argv[] ) { // Uncomment this to enable the message handler for debugging and stack tracing // qInstallMessageHandler( phoenixDebugMessageHandler ); QApplication app( argc, argv ); // On Windows, the organization domain is used to set the registry key path... for some reason QApplication::setApplicationDisplayName( QStringLiteral( "Phoenix" ) ); QApplication::setApplicationName( QStringLiteral( "Phoenix" ) ); QApplication::setApplicationVersion( QStringLiteral( "1.0" ) ); QApplication::setOrganizationDomain( QStringLiteral( "phoenix.vg" ) ); Library::PhxPaths::CreateAllPaths(); QQmlApplicationEngine engine; // Necessary to quit properly // QObject::connect( &engine, &QQmlApplicationEngine::quit, &app, &QApplication::quit ); // Register my types! VideoItem::registerTypes(); InputManager::registerTypes(); qmlRegisterSingletonType( QUrl( "qrc:/PhxTheme.qml" ), "vg.phoenix.themes", 1, 0, "PhxTheme" ); qmlRegisterType<Library::PlatformsModel>( "vg.phoenix.models", 1, 0, "PlatformsModel" ); qmlRegisterType<Library::CollectionsModel>( "vg.phoenix.models", 1, 0, "CollectionsModel" ); qmlRegisterType<Library::LibraryModel>( "vg.phoenix.models", 1, 0, "LibraryModel" ); qmlRegisterType<Library::ImageCacher>( "vg.phoenix.cache", 1, 0, "ImageCacher" ); qmlRegisterType<Library::Platform>( "vg.phoenix.models", 1, 0, "Platform" ); qRegisterMetaType<Library::GameData>( "GameData" ); engine.load( QUrl( QStringLiteral( "qrc:/main.qml" ) ) ); return app.exec(); }
int main( int argc, char *argv[] ) { // Init controller db file for backend Q_INIT_RESOURCE( controllerdb ); // Uncomment this to enable the message handler for debugging and stack tracing // qInstallMessageHandler( phoenixDebugMessageHandler ); // Handles stuff with the windowing system QGuiApplication app( argc, argv ); // The engine that runs our QML-based UI QQmlApplicationEngine engine; // Set application metadata QGuiApplication::setApplicationDisplayName( QStringLiteral( "Phoenix" ) ); QGuiApplication::setApplicationName( QStringLiteral( "Phoenix" ) ); QGuiApplication::setApplicationVersion( QStringLiteral( "0.0.1" ) ); QGuiApplication::setOrganizationName( QStringLiteral( "Team Phoenix" ) ); QGuiApplication::setOrganizationDomain( QStringLiteral( "phoenix.vg" ) ); // Figure out the right paths for the environment, and create user storage folders if not already there Library::PhxPaths::initPaths(); // For release builds, write to a log file along with the console #ifdef QT_NO_DEBUG QFile logFile( Library::PhxPaths::userDataLocation() % '/' % QStringLiteral( "Logs" ) % '/' % QDateTime::currentDateTime().toString( QStringLiteral( "ddd MMM d yyyy - h mm ss AP" ) ) % QStringLiteral( ".log" ) ); // If this fails... how would we know? :) logFile.open( QIODevice::WriteOnly | QIODevice::Text ); int logFD = logFile.handle(); logFP = fdopen( dup( logFD ), "w" ); qInstallMessageHandler( phoenixDebugMessageLog ); #endif // Open connections to the SQL databases. Library::LibretroDatabase::open(); Library::MetaDataDatabase::open(); // Necessary to quit properly QObject::connect( &engine, &QQmlApplicationEngine::quit, &app, &QGuiApplication::quit ); // Register our custom types for use within QML VideoItem::registerTypes(); InputManager::registerTypes(); // Register our custom QML-accessable/instantiable objects qmlRegisterType<Library::PlatformsModel>( "vg.phoenix.models", 1, 0, "PlatformsModel" ); qmlRegisterType<Library::CollectionsModel>( "vg.phoenix.models", 1, 0, "CollectionsModel" ); qmlRegisterType<Library::LibraryModel>( "vg.phoenix.models", 1, 0, "LibraryModel" ); qmlRegisterType<Library::CoreModel>( "vg.phoenix.models", 1, 0, "CoreModel" ); qmlRegisterType<Library::ImageCacher>( "vg.phoenix.cache", 1, 0, "ImageCacher" ); qmlRegisterType<GameLauncher>( "vg.phoenix.launcher", 1, 0, "GameLauncher" ); // Register our custom QML-accessable objects and instantiate them here qmlRegisterSingletonType( QUrl( "qrc:/PhxTheme.qml" ), "vg.phoenix.themes", 1, 0, "PhxTheme" ); qmlRegisterSingletonType<Library::PhxPaths>( "vg.phoenix.paths", 1, 0, "PhxPaths", PhxPathsSingletonProviderCallback ); qRegisterMetaType<Library::GameData>( "GameData" ); // Load the root QML object and everything under it engine.load( QUrl( QStringLiteral( "qrc:/main.qml" ) ) ); // Ensure custom controller DB file exists QFile gameControllerDBFile( Library::PhxPaths::userDataLocation() % '/' % QStringLiteral( "gamecontrollerdb.txt" ) ); if( !gameControllerDBFile.exists() ) { gameControllerDBFile.open( QIODevice::ReadWrite ); QTextStream stream( &gameControllerDBFile ); stream << "# Insert your custom definitions here" << endl; gameControllerDBFile.close(); } // Set InputManager's custom controller DB file QQmlProperty prop( engine.rootObjects().first(), "inputManager.controllerDBFile" ); Q_ASSERT( prop.isValid() ); QString path = Library::PhxPaths::userDataLocation() % QStringLiteral( "/gamecontrollerdb.txt" ); QVariant pathVar( path ); prop.write( pathVar ); // Run the app and write return code to the log file if in release mode #ifdef QT_NO_DEBUG int ret = app.exec(); fprintf( logFP, "Returned %d", ret ); fclose( logFP ); return ret; #else // Otherwise, just run it normally return app.exec(); #endif }
void QmlCovPlugin::registerTypes(const char *uri) { qmlRegisterSingletonType(uri, 1, 0, "coverage", coverage_singletontype_provider); }
void QuickIOS::registerTypes() { qmlRegisterSingletonType("QuickIOS", 0, 1, "A", aProvider); qmlRegisterType<QIAlertView>("QuickIOS",0,1,"IAlertView"); }