当前位置: 首页>>代码示例>>C++>>正文


C++ QQmlApplicationEngine::addPluginPath方法代码示例

本文整理汇总了C++中QQmlApplicationEngine::addPluginPath方法的典型用法代码示例。如果您正苦于以下问题:C++ QQmlApplicationEngine::addPluginPath方法的具体用法?C++ QQmlApplicationEngine::addPluginPath怎么用?C++ QQmlApplicationEngine::addPluginPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QQmlApplicationEngine的用法示例。


在下文中一共展示了QQmlApplicationEngine::addPluginPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[])
{
    QStringList imports, plugins;

    QGuiApplication app(argc, argv);
    app.setApplicationName("Terrarium");
    app.setOrganizationName("terrariumapp");
    app.setOrganizationDomain("terrariumapp.com");

#if defined(Q_OS_MACX)
    int platformId = 0;
#elif defined(Q_OS_IOS)
    int platformId = 1;
#elif defined(Q_OS_ANDROID)
    int platformId = 2;
#elif defined(Q_OS_LINUX)
    int platformId = 3;
#else
    int platformId = 4;
#endif 

    qmlRegisterType<QHttpServer>("HttpServer", 1, 0, "HttpServer");
    qmlRegisterType<DocumentHandler>("DocumentHandler", 1, 0, "DocumentHandler");
    qmlRegisterUncreatableType<QHttpRequest>("HttpServer", 1, 0, "HttpRequest", "Do not create HttpRequest directly");
    qmlRegisterUncreatableType<QHttpResponse>("HttpServer", 1, 0, "HttpResponse", "Do not create HttpResponse directly");

    QString platformIP; 
    foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) {
        if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost))
             platformIP = address.toString();
    }

    // Handle command line arguments
    const QStringList arguments = QCoreApplication::arguments();
    for (int i = 1, size = arguments.size(); i < size; ++i) {
      const QString lowerArgument = arguments.at(i).toLower();
      if (lowerArgument == QLatin1String("-i") && i + 1 < size) {
        imports.append(arguments.at(++i));
      } else if (lowerArgument == QLatin1String("-p") && i + 1 < size) {
        plugins.append(arguments.at(++i));
      }
    }

#if USE_WEBENGINE
    QtWebEngine::initialize();
#endif

#if QT_VERSION > QT_VERSION_CHECK(5, 1, 0)
    QQmlApplicationEngine engine;

    for(int i = 0; i < imports.size(); ++i) {
      engine.addImportPath(imports[i]);
    }
    for(int i = 0; i < plugins.size(); ++i) {
      engine.addPluginPath(plugins[i]);
    }
    engine.rootContext()->setContextProperty("platform", QVariant::fromValue(platformId));
    engine.rootContext()->setContextProperty("platformIP", QVariant::fromValue(platformIP));
    engine.rootContext()->setContextProperty("Grabber",new QuickItemGrabber(&app));
    engine.load(QUrl("qrc:///main.qml"));
#else
    QQuickView view;
    view.engine()->rootContext()->setContextProperty("platform", QVariant::fromValue(platformId));
    view.engine()->rootContext()->setContextProperty("platformIP", QVariant::fromValue(platformIP));
    view.setSource(QUrl("qrc:///main.qml"));
    view.show();
#endif 
    return app.exec();
}
开发者ID:penk,项目名称:terrarium-app,代码行数:69,代码来源:main.cpp


注:本文中的QQmlApplicationEngine::addPluginPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。