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


C++ QQmlEngine类代码示例

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


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

示例1: qDebug

//==============================================================================
// Init
//==============================================================================
void ViewerWindow::init()
{
    qDebug() << "ViewerWindow::init";

    // Set Read Only Mode
    ui->textEdit->setReadOnly(!editMode);

    // Connect Signal
    connect(ui->textEdit, SIGNAL(textChanged()), this, SLOT(textChanged()));

    // Quick Widget Set Visible
    ui->quickWidget->setVisible(true);
    // Text Edit Set Visible
    ui->textEdit->setVisible(false);

    // Set Context Properties
    QQmlContext* ctx = ui->quickWidget->rootContext();
    // Set Context Properties - Viewer Content
    ctx->setContextProperty(DEFAULT_IMAGE_VIEWER_CONTENT, fileName);

    // Get Engine
    QQmlEngine* engine = ui->quickWidget->engine();
    // Add Image Provider
    engine->addImageProvider(QLatin1String(DEFAULT_AUDIO_TAG_PROVIDER_ID), new AudioTagImageProvider());

    // Set Resize Mode
    ui->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);

    // Set Focus Policy
    setFocusPolicy(Qt::StrongFocus);

    // ...
}
开发者ID:maxavadallat,项目名称:maxcommander,代码行数:36,代码来源:viewerwindow.cpp

示例2: init

void Editor::init()
{
    if(m_initialized){
        return;
    }
    Engine* engine = Engine::getInstance();
    QQmlEngine* qmlEngine = engine->getQmlEngine();

    QQmlContext* context = qmlEngine->rootContext();
    context->setContextProperty("editor",this);

    editorUiComponent = new QQmlComponent(qmlEngine,Util::getUrlPathToAsset("qml/editor/EditorUi.qml"));

    for(QQmlError error :editorUiComponent->errors()){
        qDebug() << "Error on Line" << error.line() << ":" << error.description();
    }

    if(editorUiComponent->isReady()){
        initUi();
    }else {
        connect(editorUiComponent,SIGNAL(statusChanged(QQmlComponent::Status)),
                this,SLOT(onLoadingUiChanged(QQmlComponent::Status)));
    }

    m_initialized = true;
}
开发者ID:adderly,项目名称:VoltAir,代码行数:26,代码来源:Editor.cpp

示例3: QPointF

QQuickItem *GlobalFunctions::itemAt(QQuickItem* parent, int x, int y, QJSValue matcher)
{
    if (!parent) return nullptr;
    QList<QQuickItem *> children = QQuickItemPrivate::get(parent)->paintOrderChildItems();

    for (int i = children.count() - 1; i >= 0; --i) {
        QQuickItem *child = children.at(i);

        // Map coordinates to the child element's coordinate space
        QPointF point = parent->mapToItem(child, QPointF(x, y));
        if (child->isVisible() && point.x() >= 0
                && child->width() >= point.x()
                && point.y() >= 0
                && child->height() >= point.y()) {
            if (!matcher.isCallable()) return child;

            QQmlEngine* engine = qmlEngine(child);
            if (!engine) return child;

            QJSValue newObj = engine->newQObject(child);
            if (matcher.call(QJSValueList() << newObj).toBool()) {
                return child;
            }
        }
    }
    return nullptr;
}
开发者ID:dumpster-of-things,项目名称:unity8,代码行数:27,代码来源:globalfunctions.cpp

示例4: engineSetOwnershipJS

void engineSetOwnershipJS(QQmlEngine_ *engine, QObject_ *object)
{
    QQmlEngine *qengine = reinterpret_cast<QQmlEngine *>(engine);
    QObject *qobject = reinterpret_cast<QObject *>(object);

    qengine->setObjectOwnership(qobject, QQmlEngine::JavaScriptOwnership);
}
开发者ID:chai2010,项目名称:qml,代码行数:7,代码来源:goqml.cpp

示例5: engineAddImageProvider

void engineAddImageProvider(QQmlEngine_ *engine, QString_ *providerId, void *imageFunc)
{
    QQmlEngine *qengine = reinterpret_cast<QQmlEngine *>(engine);
    QString *qproviderId = reinterpret_cast<QString *>(providerId);

    qengine->addImageProvider(*qproviderId, new GoImageProvider(imageFunc));
}
开发者ID:chai2010,项目名称:qml,代码行数:7,代码来源:goqml.cpp

示例6: addPages

void WelcomeMode::addPages(const QList<IWelcomePage *> &pages)
{
    QList<IWelcomePage *> addedPages = pages;
    Utils::sort(addedPages, [](const IWelcomePage *l, const IWelcomePage *r) {
        return l->priority() < r->priority();
    });
    // insert into m_pluginList, keeping m_pluginList sorted by priority
    QQmlEngine *engine = m_welcomePage->engine();
    auto addIt = addedPages.begin();
    auto currentIt = m_pluginList.begin();
    while (addIt != addedPages.end()) {
        IWelcomePage *page = *addIt;
        QTC_ASSERT(!m_idPageMap.contains(page->id()), ++addIt; continue);
        while (currentIt != m_pluginList.end() && (*currentIt)->priority() <= page->priority())
            ++currentIt;
        // currentIt is now either end() or a page with higher value
        currentIt = m_pluginList.insert(currentIt, page);
        m_idPageMap.insert(page->id(), page);
        page->facilitateQml(engine);
        ++currentIt;
        ++addIt;
    }
    // update model through reset
    QQmlContext *ctx = engine->rootContext();
    ctx->setContextProperty(QLatin1String("pagesModel"), QVariant::fromValue(
                                Utils::transform(m_pluginList, // transform into QList<QObject *>
                                                 [](IWelcomePage *page) -> QObject * {
                                    return page;
                                })));
}
开发者ID:raphaelcotty,项目名称:qt-creator,代码行数:30,代码来源:welcomeplugin.cpp

示例7: main

int main(int argc, char ** argv)
{
	QApplication app(argc, argv);

	qmlRegisterType<Hider>("com.ics.demo", 1, 0, "Hider");

	int rc = 0;

	QQmlEngine engine;
	QQmlComponent *component = new QQmlComponent(&engine);

	QObject::connect(&engine, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));

    component->loadUrl(QUrl("../../Source/main.qml"));

	Hider::image_provider = new ImageProvider;
	engine.addImageProvider("images", Hider::image_provider);

	if (!component->isReady() ) {
		qWarning("%s", qPrintable(component->errorString()));
		return -1;
	}

	QObject *topLevel = component->create();
	QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);

	QSurfaceFormat surfaceFormat = window->requestedFormat();
	window->setFormat(surfaceFormat);
	window->show();

	rc = app.exec();

	delete component;
	return rc;
}
开发者ID:stanislavp,项目名称:GraduationProject,代码行数:35,代码来源:main.cpp

示例8: QCOMPARE

void tst_QQmlPropertyMap::controlledWrite()
{
    MyPropertyMap map;
    QCOMPARE(map.isEmpty(), true);

    //make changes in QML
    QQmlEngine engine;
    QQmlContext *ctxt = engine.rootContext();
    ctxt->setContextProperty(QLatin1String("testdata"), &map);

    const char *qmlSource =
        "import QtQuick 2.0\n"
        "Item { Component.onCompleted: { testdata.key1 = 'Hello World'; testdata.key2 = 'Goodbye' } }";

    QQmlComponent component(&engine);
    component.setData(qmlSource, QUrl::fromLocalFile(""));
    QVERIFY(component.isReady());

    QObject *obj = component.create();
    QVERIFY(obj);
    delete obj;

    QCOMPARE(map.value(QLatin1String("key1")), QVariant("HELLO WORLD"));
    QCOMPARE(map.value(QLatin1String("key2")), QVariant("Goodbye"));
}
开发者ID:ghjinlei,项目名称:qt5,代码行数:25,代码来源:tst_qqmlpropertymap.cpp

示例9: syntaxError

// QTBUG-21310 - crash test
void tst_qqmlexpression::syntaxError()
{
    QQmlEngine engine;
    QQmlExpression expression(engine.rootContext(), 0, "asd asd");
    QVariant v = expression.evaluate();
    QCOMPARE(v, QVariant());
}
开发者ID:SamuelNevala,项目名称:qtdeclarative,代码行数:8,代码来源:tst_qqmlexpression.cpp

示例10: TEST_FILE

void TestSimpleQmlLoad::compileAndLoadSignal2()
{
    const QString TEST_FILE(":/testqml/testsignal2.qml");

    QQmlEngine *engine = new QQmlEngine;
    QQmlComponent* component = compileAndLoad(engine, TEST_FILE);
    QVERIFY(component);

    SignalTester st;

    engine->rootContext()->setContextProperty("st", &st);

    QObject *myObject = component->create();
    QVERIFY(myObject != NULL);

    QVariant var = myObject->property("sigReceived");
    QVERIFY(!var.isNull());
    QVERIFY(var.toBool() == false);

    st.sendSig();
    var = myObject->property("sigReceived");
    QVERIFY(!var.isNull());
    QVERIFY(var.toBool() == true);

    delete component;
    delete engine;
}
开发者ID:RichardsATcn,项目名称:qmlc,代码行数:27,代码来源:testsimpleqmlload.cpp

示例11: spy

void tst_QQmlPropertyMap::changed()
{
    QQmlPropertyMap map;
    QSignalSpy spy(&map, SIGNAL(valueChanged(const QString&, const QVariant&)));
    map.insert(QLatin1String("key1"),100);
    map.insert(QLatin1String("key2"),200);
    QCOMPARE(spy.count(), 0);

    map.clear(QLatin1String("key1"));
    QCOMPARE(spy.count(), 0);

    //make changes in QML
    QQmlEngine engine;
    QQmlContext *ctxt = engine.rootContext();
    ctxt->setContextProperty(QLatin1String("testdata"), &map);
    QQmlComponent component(&engine);
    component.setData("import QtQuick 2.0\nText { text: { testdata.key1 = 'Hello World'; 'X' } }",
            QUrl::fromLocalFile(""));
    QVERIFY(component.isReady());
    QQuickText *txt = qobject_cast<QQuickText*>(component.create());
    QVERIFY(txt);
    QCOMPARE(txt->text(), QString('X'));
    QCOMPARE(spy.count(), 1);
    QList<QVariant> arguments = spy.takeFirst();
    QCOMPARE(arguments.count(), 2);
    QCOMPARE(arguments.at(0).toString(),QLatin1String("key1"));
    QCOMPARE(arguments.at(1).value<QVariant>(),QVariant("Hello World"));
    QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World"));
}
开发者ID:ghjinlei,项目名称:qt5,代码行数:29,代码来源:tst_qqmlpropertymap.cpp

示例12: offlineStoragePath

void tst_qqmlengine::offlineStoragePath()
{
    // Without these set, QDesktopServices::storageLocation returns
    // strings with extra "//" at the end. We set them to ignore this problem.
    qApp->setApplicationName("tst_qqmlengine");
    qApp->setOrganizationName("QtProject");
    qApp->setOrganizationDomain("www.qt-project.org");

    QQmlEngine engine;

    QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);

    QCOMPARE(dataLocation.isEmpty(), engine.offlineStoragePath().isEmpty());

    QDir dir(dataLocation);
    dir.mkpath("QML");
    dir.cd("QML");
    dir.mkpath("OfflineStorage");
    dir.cd("OfflineStorage");

    QCOMPARE(QDir::fromNativeSeparators(engine.offlineStoragePath()), dir.path());

    engine.setOfflineStoragePath(QDir::homePath());
    QCOMPARE(engine.offlineStoragePath(), QDir::homePath());
}
开发者ID:2gis,项目名称:2gisqt5android,代码行数:25,代码来源:tst_qqmlengine.cpp

示例13: main

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QQmlEngine engine;
    QMLBattleStationContext* context = new QMLBattleStationContext();
    engine.rootContext()->setContextProperty(QString("context"), context);
    QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/main.qml")));
    component.create();
    //  Init/create subsystems
    if (SDL_Init(SDL_INIT_JOYSTICK)) {
        QString* err = new QString(SDL_GetError());
        qWarning() << LOG_ERROR << "SDL init error:" << err;
        //  TODO UI notification
    } else {
        qDebug() << LOG_OK << "SDL init";
    }
    Serial* serial = new Serial();
    InputHandler* inputHandler = new InputHandler();

    //  Connect Serial and BSC
    QObject::connect(context, SIGNAL(SelectedSerialDeviceChanged(QString)),
                     serial, SLOT(SetActiveSerialDevice(QString)));
    //  Connect Input and BSC
    QObject::connect(context, SIGNAL(SelectedJoystickAChanged(QString)),
                     inputHandler, SLOT(SetMainJoystick(QString*)));
    //  Connect Input to Serial
    QObject::connect(inputHandler, SIGNAL(MotorValuesChanged(quint8[])),
                     serial, SLOT(SetMotorValues(quint8[])));
    QObject::connect(inputHandler, SIGNAL(PostToolUpdate(quint16,quint16)),
                     serial, SLOT(EnqueueToolEvent(quint16,quint16)));


    return app.exec();
}
开发者ID:coleelam,项目名称:Cerulean-BattleStation,代码行数:34,代码来源:main.cpp

示例14: engineSetContextForObject

void engineSetContextForObject(QQmlEngine_ *engine, QObject_ *object)
{
    QQmlEngine *qengine = reinterpret_cast<QQmlEngine *>(engine);
    QObject *qobject = reinterpret_cast<QObject *>(object);

    QQmlEngine::setContextForObject(qobject, qengine->rootContext());
}
开发者ID:chai2010,项目名称:qml,代码行数:7,代码来源:goqml.cpp

示例15: main

int main(int argc, char **argv)
{
  QApplication app(argc, argv);

  const QUrl documentUrl = QUrl("qrc:///main.qml");

  QQmlEngine engine;
#ifdef Q_OS_MACOS
  engine.addImportPath(QStringLiteral("%1/../PlugIns").arg(QCoreApplication::applicationDirPath()));
#else
  engine.addImportPath(PLUGIN_IMPORT_PATH);
#endif
  Editor editor;
  engine.rootContext()->setContextProperty("_editor", &editor);
  QObject::connect(&engine, &QQmlEngine::quit, QCoreApplication::instance(), &QCoreApplication::quit);

  QQmlComponent component(&engine, documentUrl);
  QWidget *widget = qobject_cast<QWidget*>(component.create());
  if (!widget)
    qFatal("Failed to create widget from QML");
    
  widget->show();

  return app.exec();
}
开发者ID:KDAB,项目名称:DeclarativeWidgets,代码行数:25,代码来源:main.cpp


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