本文整理汇总了C++中QtQuick2ApplicationViewer::engine方法的典型用法代码示例。如果您正苦于以下问题:C++ QtQuick2ApplicationViewer::engine方法的具体用法?C++ QtQuick2ApplicationViewer::engine怎么用?C++ QtQuick2ApplicationViewer::engine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QtQuick2ApplicationViewer
的用法示例。
在下文中一共展示了QtQuick2ApplicationViewer::engine方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv); // Create the base application class
QtQuick2ApplicationViewer viewer; // create the QML viewer window
// The below code will eventually be wrapped in a top level class
// Initialize the flyweight
//Create first Variable "A"
Var* current_var(nullptr);
CalculationFlyWeight flyweight;
QString token(flyweight.insertCalculation("0","A",current_var));
// Initialize the InputEventHandle class connects QML user input -> C++ Backend logic
InputEventHandler in(&flyweight,viewer.engine()->rootContext(),&viewer,nullptr,current_var);
// Make the Event Handler visible as QObject& in QML
viewer.engine()->rootContext()->setContextProperty("EventHandler",&in);
// simulate a user input call to place A as the current variable in the editor
in.requestVariable(token);
// set the main qml file
viewer.setMainQmlFile(QStringLiteral("User_Interface/qml/main.qml"));
viewer.showExpanded(); // set fullscreen, and visible
return app.exec(); // run the main Application Event loop
}
示例2: main
int main(int argc, char *argv[])
{
qDebug("[Salticidae] Init Salticidae v%s", PROJECT_VERSION);
QCoreApplication::setOrganizationName("Rabits");
QCoreApplication::setOrganizationDomain("rabits.org");
QCoreApplication::setApplicationName("salticidae");
QCoreApplication::setApplicationVersion(PROJECT_VERSION);
QGuiApplication app(argc, argv);
Eyes::registerQmlTypes();
PluginManager::initPlugins();
QtQuick2ApplicationViewer viewer;
Eyes::I()->initContext(viewer, &app);
qDebug("[Salticidae] Loading qml");
viewer.setSource(QUrl("qrc:/qml/salticidae/main.qml"));
QObject::connect(viewer.engine(), SIGNAL(quit()), &viewer, SLOT(close()));
Eyes::I()->initRoot(viewer);
qDebug("[Salticidae] Init done, starting");
viewer.showExpanded();
return app.exec();
}
示例3: main
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QString fileName;
if (app.arguments().length() > 1) {
fileName = app.arguments().at(1);
} else {
qWarning() << "Pass extracted json memory info dump as argument";
return 0;
}
QtQuick2ApplicationViewer viewer;
QFile jsonFile(fileName);
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Failed to open file:" << fileName;
return 0;
}
viewer.setTitle(fileName);
viewer.engine()->rootContext()->setContextProperty("jsonFile", QString(jsonFile.readAll()));
viewer.setMainQmlFile(QStringLiteral("qml/memory-dump-reader.qml"));
viewer.showExpanded();
return app.exec();
}
示例4: main
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
qmlRegisterType<PieSlice>("Charts", 1, 0, "PieSlice");
Configuration m_configuration;
SerialLink m_serialLink;
MavLinkManager m_mavlink_manager;
LinkManager m_gLinkManager;
QtQuick2ApplicationViewer viewer;
QtQuick2ApplicationViewer splashscreen;
QString customPath = "Sqlite/OfflineStorage";
QDir dir;
if(dir.mkpath(QString(customPath))){
// qDebug() << "Default path >> "+viewer.engine()->offlineStoragePath();
viewer.engine()->setOfflineStoragePath(QString(customPath));
// qDebug() << "New path >> "+viewer.engine()->offlineStoragePath();
}
// using as normal
// viewer.setMainQmlFile(QStringLiteral("qml/gStabiSC/main.qml"));
// using qml files form resources file, uncomment this to compile all qml file to .exe
splashscreen.setSource(QUrl("qrc:/qml/gStabiSC/GSplashScreen.qml"));
splashscreen.setFlags(Qt::FramelessWindowHint);
splashscreen.setMinimumSize(QSize(1000,500));
splashscreen.show();
viewer.setSource(QUrl("qrc:/qml/gStabiSC/GMain.qml"));
viewer.setTitle(QString("%1 %2").arg(APPLICATION_NAME).arg(APPLICATION_VERSION));
viewer.setMinimumSize(QSize(APPLICATION_WIDTH,APPLICATION_HEIGHT));
viewer.setMaximumSize(QSize(APPLICATION_WIDTH,APPLICATION_HEIGHT));
// viewer.addImportPath("qrc:/qml/gStabiSC");
// viewer.addImportPath("qrc:/qml/gStabiSC/Components");
// viewer.addImportPath("qrc:/qml/gStabiSC/GDashboard");
// viewer.addImportPath("qrc:/javascript/storage.js");
viewer.rootContext()->setContextProperty("_configuration",&m_configuration);
viewer.rootContext()->setContextProperty("_serialLink", &m_serialLink);
viewer.rootContext()->setContextProperty("_mavlink_manager", &m_mavlink_manager);
m_gLinkManager.connectLink(&m_serialLink,&m_mavlink_manager);
QTimer::singleShot(3000, &splashscreen, SLOT(close()));
QTimer::singleShot(3000, &viewer, SLOT(show()));
return app.exec();
}
示例5: main
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QString filepath = app.arguments().value(1, "./why_are_you_reading_this.png");
filepath = QDir().absoluteFilePath(filepath);
Comic comic;
if (QFile(filepath).exists()) {
comic.load(QImage(filepath));
} else {
qDebug() << "File does not exist:" << filepath;
}
QtQuick2ApplicationViewer viewer;
viewer.engine()->addImageProvider("comicimageprovider", new ComicImageProvider(comic));
QQmlContext* context = viewer.rootContext();
context->setContextProperty("comic", &comic);
viewer.setMainQmlFile(QStringLiteral("qml/quick/main.qml"));
viewer.showExpanded();
return app.exec();
}
示例6: main
int main(int argc, char *argv[]) {
QGuiApplication app(argc, argv);
Utility::registerTypes();
qmlRegisterType<BarcodeObject>("KoboMan", 1, 0, "Barcode");
qmlRegisterType<BarcodeScanner>("KoboMan", 1, 0, "BarcodeScanner");
QtQuick2ApplicationViewer viewer;
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
viewer.addImportPath(QStringLiteral("assets:/imports"));
#else
viewer.addImportPath(QStringLiteral("imports"));
#endif
qDebug() << viewer.engine()->importPathList();
Utility::initialize(&viewer);
Theme::initialize(Theme::androidHoloLight());
BookListModel bookList;
viewer.rootContext()->setContextProperty("BookList", &bookList);
viewer.rootContext()->setContextProperty("Library", &Library::get());
viewer.setMainQmlFile(QStringLiteral("qml/koboman/main.qml"));
viewer.showExpanded();
return app.exec();
}
示例7: main
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
//QQuickView viewer;
QtQuick2ApplicationViewer viewer;
viewer.connect(viewer.engine(),SIGNAL(quit()),
&viewer,SLOT(close()));
/* 调用本地Android java API实现通知栏 */
// NotificationClient *notificationClient = new NotificationClient(&viewer);
// viewer.engine()->rootContext()->setContextProperty(QLatin1String("notificationClient"),
// notificationClient);
// viewer.engine()->rootContext()->setContextProperty(QLatin1String("mainview"),
// &viewer);
//viewer.setVisibility(QWindow::FullScreen);
// viewer.setResizeMode(QQuickView::SizeRootObjectToView);
//viewer.setSource(QUrl(QStringLiteral("qrc:/qml/NotifyTest/init.qml")));
viewer.setMainQmlFile(QLatin1String("qml/NotifyTest/init.qml"));
viewer.showExpanded();
//viewer.showFullScreen();
return app.exec();
}
示例8: main
int main(int argc, char *argv[])
{
QOptions options(get_common_options());
options.add(QLatin1String("QMLPlayer options"))
("scale", 1.0, QLatin1String("scale of graphics context. 0: auto"))
;
options.parse(argc, argv);
if (options.value(QLatin1String("help")).toBool()) {
options.print();
return 0;
}
QGuiApplication app(argc, argv);
QDir::setCurrent(qApp->applicationDirPath());
qDebug() << "arguments======= " << app.arguments();
set_opengl_backend(options.option(QStringLiteral("gl")).value().toString(), app.arguments().first());
load_qm(QStringList() << QStringLiteral("QMLPlayer"), options.value(QStringLiteral("language")).toString());
QtQuick2ApplicationViewer viewer;
QString binDir = qApp->applicationDirPath();
if (binDir.endsWith(QLatin1String(".app/Contents/MacOS"))) {
binDir.remove(QLatin1String(".app/Contents/MacOS"));
binDir = binDir.left(binDir.lastIndexOf(QLatin1String("/")));
}
QQmlEngine *engine = viewer.engine();
if (!engine->importPathList().contains(binDir))
engine->addImportPath(binDir);
qDebug() << engine->importPathList();
engine->rootContext()->setContextProperty(QStringLiteral("PlayerConfig"), &Config::instance());
qDebug(">>>>>>>>devicePixelRatio: %f", qApp->devicePixelRatio());
QScreen *sc = app.primaryScreen();
qDebug() << "dpi phy: " << sc->physicalDotsPerInch() << ", logical: " << sc->logicalDotsPerInch() << ", dpr: " << sc->devicePixelRatio()
<< "; vis rect:" << sc->virtualGeometry();
// define a global var for js and qml
engine->rootContext()->setContextProperty(QStringLiteral("screenPixelDensity"), qApp->primaryScreen()->physicalDotsPerInch()*qApp->primaryScreen()->devicePixelRatio());
qreal r = sc->physicalDotsPerInch()/sc->logicalDotsPerInch();
if (std::isinf(r) || std::isnan(r))
#if defined(Q_OS_ANDROID)
r = 2.0;
#else
r = 1.0;
#endif
float sr = options.value(QStringLiteral("scale")).toFloat();
#if defined(Q_OS_ANDROID)
sr = r;
if (sr > 2.0)
sr = 2.0; //FIXME
#endif
if (qFuzzyIsNull(sr))
sr = r;
engine->rootContext()->setContextProperty(QStringLiteral("scaleRatio"), sr);
QString qml = QStringLiteral("qml/QMLPlayer/main.qml");
if (QFile(qApp->applicationDirPath() + QLatin1String("/") + qml).exists())
qml.prepend(qApp->applicationDirPath() + QLatin1String("/"));
else
qml.prepend(QLatin1String("qrc:///"));
viewer.setMainQmlFile(qml);
viewer.show();
QOption op = options.option(QStringLiteral("width"));
if (op.isSet())
viewer.setWidth(op.value().toInt());
op = options.option(QStringLiteral("height"));
if (op.isSet())
viewer.setHeight(op.value().toInt());
op = options.option(QStringLiteral("x"));
if (op.isSet())
viewer.setX(op.value().toInt());
op = options.option(QStringLiteral("y"));
if (op.isSet())
viewer.setY(op.value().toInt());
if (options.value(QStringLiteral("fullscreen")).toBool())
viewer.showFullScreen();
viewer.setTitle(QStringLiteral("QMLPlayer based on QtAV. [email protected]"));
/*
* find root item, then root.init(argv). so we can deal with argv in qml
*/
#if 1
QString json = app.arguments().join(QStringLiteral("\",\""));
json.prepend(QLatin1String("[\"")).append(QLatin1String("\"]"));
json.replace(QLatin1String("\\"), QLatin1String("/")); //FIXME
QMetaObject::invokeMethod(viewer.rootObject(), "init", Q_ARG(QVariant, json));
//#else
QObject *player = viewer.rootObject()->findChild<QObject*>(QStringLiteral("player"));
if (player) {
AppEventFilter *ae = new AppEventFilter(player, player);
qApp->installEventFilter(ae);
}
QString file;
#ifdef Q_OS_ANDROID
file = QAndroidJniObject::callStaticObjectMethod("org.qtav.qmlplayer.QMLPlayerActivity"
, "getUrl"
, "()Ljava/lang/String;")
.toString();
#endif
if (app.arguments().size() > 1) {
file = options.value(QStringLiteral("file")).toString();
if (file.isEmpty()) {
if (argc > 1 && !app.arguments().last().startsWith(QLatin1Char('-')) && !app.arguments().at(argc-2).startsWith(QLatin1Char('-')))
file = app.arguments().last();
}
//.........这里部分代码省略.........
示例9: main
int main(int argc, char *argv[])
{
QOptions options(get_common_options());
options.add("QMLPlayer options")
("scale", 1.0, "scale of graphics context. 0: auto")
;
options.parse(argc, argv);
if (options.value("help").toBool()) {
options.print();
return 0;
}
QGuiApplication app(argc, argv);
QtQuick2ApplicationViewer viewer;
qDebug(">>>>>>>>devicePixelRatio: %f", qApp->devicePixelRatio());
QScreen *sc = app.primaryScreen();
qDebug() << "dpi phy: " << sc->physicalDotsPerInch() << ", logical: " << sc->logicalDotsPerInch() << ", dpr: " << sc->devicePixelRatio()
<< "; vis rect:" << sc->virtualGeometry();
// define a global var for js and qml
viewer.engine()->rootContext()->setContextProperty("screenPixelDensity", qApp->primaryScreen()->physicalDotsPerInch()*qApp->primaryScreen()->devicePixelRatio());
qreal r = sc->physicalDotsPerInch()/sc->logicalDotsPerInch();
if (std::isinf(r) || std::isnan(r))
#if defined(Q_OS_ANDROID)
r = 2.0;
#else
r = 1.0;
#endif
float sr = options.value("scale").toFloat();
if (qFuzzyIsNull(sr))
sr = r;
viewer.engine()->rootContext()->setContextProperty("scaleRatio", sr);
QString qml = "qml/QMLPlayer/main.qml";
if (QFile(qApp->applicationDirPath() + "/" + qml).exists())
qml.prepend(qApp->applicationDirPath() + "/");
else
qml.prepend("qrc:///");
viewer.setMainQmlFile(qml);
viewer.showExpanded();
QOption op = options.option("width");
if (op.isSet())
viewer.setWidth(op.value().toInt());
op = options.option("height");
if (op.isSet())
viewer.setHeight(op.value().toInt());
op = options.option("x");
if (op.isSet())
viewer.setX(op.value().toInt());
op = options.option("y");
if (op.isSet())
viewer.setY(op.value().toInt());
if (options.value("fullscreen").toBool())
viewer.showFullScreen();
viewer.setTitle("QMLPlayer based on QtAV. [email protected]");
/*
* find root item, then root.init(argv). so we can deal with argv in qml
*/
#if 1
QString json = app.arguments().join("\",\"");
json.prepend("[\"").append("\"]");
json.replace("\\", "/"); //FIXME
QMetaObject::invokeMethod(viewer.rootObject(), "init", Q_ARG(QVariant, json));
//#else
if (app.arguments().size() > 1) {
qDebug("arguments > 1");
QObject *player = viewer.rootObject()->findChild<QObject*>("player");
QString file = options.value("file").toString();
if (player && !file.isEmpty()) {
if (QFile(file).exists())
file.prepend("file://");
file.replace("\\", "/"); //qurl
QMetaObject::invokeMethod(player, "play", Q_ARG(QUrl, QUrl(file)));
}
}
#endif
QObject::connect(viewer.rootObject(), SIGNAL(requestFullScreen()), &viewer, SLOT(showFullScreen()));
QObject::connect(viewer.rootObject(), SIGNAL(requestNormalSize()), &viewer, SLOT(showNormal()));
ScreenSaver::instance().disable(); //restore in dtor
return app.exec();
}