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


C++ QDeclarativeEngine::rootContext方法代码示例

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


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

示例1: contextForObject

void tst_qdeclarativeengine::contextForObject()
{
    QDeclarativeEngine *engine = new QDeclarativeEngine;

    // Test null-object
    QVERIFY(QDeclarativeEngine::contextForObject(0) == 0);

    // Test an object with no context
    QObject object;
    QVERIFY(QDeclarativeEngine::contextForObject(&object) == 0);

    // Test setting null-object
    QDeclarativeEngine::setContextForObject(0, engine->rootContext());

    // Test setting null-context
    QDeclarativeEngine::setContextForObject(&object, 0);

    // Test setting context
    QDeclarativeEngine::setContextForObject(&object, engine->rootContext());
    QVERIFY(QDeclarativeEngine::contextForObject(&object) == engine->rootContext());

    QDeclarativeContext context(engine->rootContext());

    // Try changing context
    QTest::ignoreMessage(QtWarningMsg, "QDeclarativeEngine::setContextForObject(): Object already has a QDeclarativeContext");
    QDeclarativeEngine::setContextForObject(&object, &context);
    QVERIFY(QDeclarativeEngine::contextForObject(&object) == engine->rootContext());

    // Delete context
    delete engine; engine = 0;
    QVERIFY(QDeclarativeEngine::contextForObject(&object) == 0);
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:32,代码来源:tst_qdeclarativeengine.cpp

示例2: rootContext

void tst_qdeclarativeengine::rootContext()
{
    QDeclarativeEngine engine;

    QVERIFY(engine.rootContext());

    QCOMPARE(engine.rootContext()->engine(), &engine);
    QVERIFY(engine.rootContext()->parentContext() == 0);
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:9,代码来源:tst_qdeclarativeengine.cpp

示例3: main

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

    QDeclarativeView view;

    QDeclarativeEngine *engine = view.engine();

    AccelerometerReader reader;

    engine->rootContext()->setContextProperty("accelerometerReader", &reader);

    view.setSource(QUrl("qrc:/Gui.qml"));
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);

#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
    view.setGeometry(QApplication::desktop()->screenGeometry());
    view.showFullScreen();
#else
    view.setGeometry((QRect(100, 100, 800, 480)));
    view.show();
#endif

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

示例4: changed

void tst_QDeclarativePropertyMap::changed()
{
    QDeclarativePropertyMap 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
    QDeclarativeEngine engine;
    QDeclarativeContext *ctxt = engine.rootContext();
    ctxt->setContextProperty(QLatin1String("testdata"), &map);
    QDeclarativeComponent component(&engine);
    component.setData("import QtQuick 1.0\nText { text: { testdata.key1 = 'Hello World'; 'X' } }",
            QUrl::fromLocalFile(""));
    QVERIFY(component.isReady());
    QDeclarativeText *txt = qobject_cast<QDeclarativeText*>(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:Drakey83,项目名称:steamlink-sdk,代码行数:29,代码来源:tst_qdeclarativepropertymap.cpp

示例5: QObject

SFAbstractApplicationUI::SFAbstractApplicationUI(bb::cascades::Application *app) : QObject(app) {

	//register meta types for SF classes and enums
	sfRegisterMetaTypes();

	//Setup SFDC connection info
	SFAccountManager::setClientId(SFRemoteAccessConsumerKey);
	SFAccountManager::setRedirectUri(SFOAuthRedirectURI);
	//In addition, you can set up scope for your token like below.
	/*
	QList<QString> scopes;
	scopes.append("api");
	SFAccountManager::setScopes(scopes);
	*/

	//setup API objects
	SFRestAPI::instance()->setApiVersion(SFDefaultRestApiVersion);

	//Expose API objects to QML
	QDeclarativeEngine *engine = QmlDocument::defaultDeclarativeEngine();
	QDeclarativeContext *context = engine ? engine->rootContext() : NULL;
	if (context) {
		context->setContextProperty("SFAccountManager", SFAccountManager::instance());
		context->setContextProperty("SFAuthenticationManager", SFAuthenticationManager::instance());
		context->setContextProperty("SFRestAPI", SFRestAPI::instance());
	} else {
		sfWarning() << "[SFAbstractApplicationUI] Failed to grab shared QML declarative engine. SF APIs may not be accessible in QML.";
	}

	//connect some slots
	connect(app, SIGNAL(aboutToQuit()), SFAuthenticationManager::instance(), SLOT(onAboutToQuit()));
	connect(app, SIGNAL(fullscreen()), SFAuthenticationManager::instance(), SLOT(onAppStart()));
}
开发者ID:blackberry,项目名称:BlackBerry10SDK-for-SalesforceMobile,代码行数:33,代码来源:SFAbstractApplicationUI.cpp

示例6: DockModeWindow

DockModeClockWindow::DockModeClockWindow(const QPixmap& pixmap, DockModeWindowManager* dm, int zValue)
	: DockModeWindow (WindowType::Type_DockModeWindow, pixmap)
{
	setFlag (QGraphicsItem::ItemHasNoContents);
	setBoundingRect (pixmap.width(), pixmap.height());

	setName (LOCALIZED("Time"));
	setAppId ("com.palm.dockmodetime");

	QDeclarativeEngine* qmlEngine = WindowServer::instance()->declarativeEngine();
	if(qmlEngine) {
		QDeclarativeContext* context =	qmlEngine->rootContext();
		Settings* settings = Settings::LunaSettings();
		std::string systemMenuQmlPath = settings->lunaQmlUiComponentsPath + "DockModeTime/Clocks.qml";
		QUrl url = QUrl::fromLocalFile(systemMenuQmlPath.c_str());
		m_qmlNotifMenu = new QDeclarativeComponent(qmlEngine, url, this);
		if(m_qmlNotifMenu) {
			m_clockObject = qobject_cast<QGraphicsObject *>(m_qmlNotifMenu->create());
			if(m_clockObject) {
				m_clockObject->setPos (boundingRect().x(), boundingRect().y());
				m_clockObject->setParentItem(this);
			}
		}
	}
}
开发者ID:KyleMaas,项目名称:luna-sysmgr,代码行数:25,代码来源:DockModeClock.cpp

示例7: component

MainWindow::MainWindow(QGraphicsScene *parent) :
    QGraphicsView(parent) {

    QGraphicsScene *mainScene = new QGraphicsScene;
    setScene(mainScene);
    setFrameShape(QFrame::NoFrame);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    setCacheMode( QGraphicsView::CacheBackground );
    setAttribute(Qt::WA_TranslucentBackground, false);
    setBackgroundBrush(QBrush(Qt::black, Qt::SolidPattern));

    QDir templateDir = QApplication::applicationDirPath();
    templateDir.cdUp();
    templateDir.cd("app");

    qDebug() << "Loading file: " << templateDir.filePath("index.html");

    QGraphicsScene *scene = new QGraphicsScene;
    QDeclarativeEngine *engine = new QDeclarativeEngine;
    QDeclarativeComponent component(engine, QUrl::fromLocalFile(QApplication::applicationDirPath() + QLatin1String("/../qml/browser.qml")));
    qDebug() << component.errors();

    notifier = new Notifier();
    QObject *comp = component.create();
    QMLDialog = comp->findChild<QDeclarativeItem*>("dialog");
    QMLGallery = comp->findChild<QDeclarativeItem*>("gallery");
    QMLWebView = comp->findChild<QDeclarativeItem*>("webView");
    engine->rootContext()->setContextProperty("notifier", notifier);

    ((QDeclarativeWebView*) QMLWebView)->setPage(new WebPage());
    QMLWebView->setProperty("pageUrl", "../app/index.html");
    ((QDeclarativeWebView*) QMLWebView)->page()->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
    ((QDeclarativeWebView*) QMLWebView)->page()->settings()->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true);
    ((QDeclarativeWebView*) QMLWebView)->page()->settings()->setAttribute(QWebSettings::AcceleratedCompositingEnabled, true);
    ((QDeclarativeWebView*) QMLWebView)->page()->settings()->setAttribute(QWebSettings::TiledBackingStoreEnabled, true);
    ((QDeclarativeWebView*) QMLWebView)->settings()->enablePersistentStorage();
    QMLWebView->setCacheMode(QGraphicsItem::DeviceCoordinateCache);

    new Extensions(((QDeclarativeWebView*) QMLWebView));

    scene->addItem(qobject_cast<QGraphicsItem*>(comp));
    scene->setSceneRect(0,0,width(),height());
    scene->setItemIndexMethod(QGraphicsScene::NoIndex);

    QMLView = new QGraphicsView( this );
    QMLView->setScene( scene );
    QMLView->setGeometry(0,0,width(),height());
    QMLView->setStyleSheet( "background: transparent; border: none;" );
    QMLView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    QMLView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    QMLView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    QMLView->setCacheMode( QGraphicsView::CacheBackground );
    QMLView->setFrameShape(QFrame::NoFrame);

    ((QDeclarativeWebView*) QMLWebView)->page()->mainFrame()->evaluateJavaScript("window._nativeReady = true"); // Tell PhoneGap that init is complete.
}
开发者ID:bundyo,项目名称:phonegap,代码行数:58,代码来源:mainwindow.cpp

示例8: alternative

static void alternative()
{
    // Alternatively, if we don't actually want to display main.qml:
//![1]
    QDeclarativeEngine engine;
    QDeclarativeContext *windowContext = new QDeclarativeContext(engine.rootContext());
    windowContext->setContextProperty("backgroundColor", QColor(Qt::yellow));

    QDeclarativeComponent component(&engine, "main.qml");
    QObject *window = component.create(windowContext);
//![1]
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.vendor,代码行数:12,代码来源:main.cpp

示例9: main

QTM_USE_NAMESPACE

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QCoreApplication::setOrganizationName("Synchroma");
    QCoreApplication::setOrganizationDomain("synchroma.com.au");
    QCoreApplication::setApplicationName("Arca");

    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QmlApplicationViewer viewer;

    QDeclarativeEngine *engine = viewer.engine();
    QDeclarativeContext *context = engine->rootContext();

    DBSession session;
    session.setConsumerKey(DROPBOX_APP_KEY);
    session.setConsumerSecret(DROPBOX_APP_SECRET);

    // Have the REST client visible in the QML
    DBRestClient restClient(session);
    context->setContextProperty("restClient", &restClient);

    // TESTING
    context->setContextProperty("param", QString(argv[1]));

    // TESTING
    qDebug() << "temp dir: " << QDir::tempPath();
    qDebug() << "home dir: " << QDir::homePath();
    qDebug() << "current dir: " << QDir::currentPath();

    QServiceManager serviceManager(QService::SystemScope);
    QStringList stringList = serviceManager.findServices();
    foreach (QString interfaceName, stringList)
        qDebug() << "service interface: " << interfaceName;

    QList<QServiceInterfaceDescriptor> descriptors = serviceManager.findInterfaces();
    for (int i=0; i<descriptors.count(); i++)
    {
        QString service = descriptors[i].serviceName();

        if (descriptors[i].scope() == QService::SystemScope)
            service += " (system)";

        qDebug() << "service: " << service;
    }

    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qml/arca/main.qml"));
    viewer.showExpanded();

    return app->exec();
}
开发者ID:chegestar,项目名称:arca,代码行数:52,代码来源:main.cpp

示例10: baseUrl

void tst_qdeclarativeengine::baseUrl()
{
    QDeclarativeEngine engine;

    QUrl cwd = QUrl::fromLocalFile(QDir::currentPath() + QDir::separator());

    QCOMPARE(engine.baseUrl(), cwd);
    QCOMPARE(engine.rootContext()->resolvedUrl(QUrl("main.qml")), cwd.resolved(QUrl("main.qml")));

    QDir dir = QDir::current();
    dir.cdUp();
    QVERIFY(dir != QDir::current());
    QDir::setCurrent(dir.path());
    QVERIFY(QDir::current() == dir);

    QUrl cwd2 = QUrl::fromLocalFile(QDir::currentPath() + QDir::separator());
    QCOMPARE(engine.baseUrl(), cwd2);
    QCOMPARE(engine.rootContext()->resolvedUrl(QUrl("main.qml")), cwd2.resolved(QUrl("main.qml")));

    engine.setBaseUrl(cwd);
    QCOMPARE(engine.baseUrl(), cwd);
    QCOMPARE(engine.rootContext()->resolvedUrl(QUrl("main.qml")), cwd.resolved(QUrl("main.qml")));
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:23,代码来源:tst_qdeclarativeengine.cpp

示例11: progressAndStatusChanges

void tst_qsganimatedimage::progressAndStatusChanges()
{
    TestHTTPServer server(14449);
    QVERIFY(server.isValid());
    server.serveDirectory(SRCDIR "/data");

    QDeclarativeEngine engine;
    QString componentStr = "import QtQuick 2.0\nAnimatedImage { source: srcImage }";
    QDeclarativeContext *ctxt = engine.rootContext();
    ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(SRCDIR "/data/stickman.gif"));
    QDeclarativeComponent component(&engine);
    component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
    QSGImage *obj = qobject_cast<QSGImage*>(component.create());
    QVERIFY(obj != 0);
    QVERIFY(obj->status() == QSGImage::Ready);
    QTRY_VERIFY(obj->progress() == 1.0);

    QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(const QUrl &)));
    QSignalSpy progressSpy(obj, SIGNAL(progressChanged(qreal)));
    QSignalSpy statusSpy(obj, SIGNAL(statusChanged(QSGImageBase::Status)));

    // Loading local file
    ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(SRCDIR "/data/colors.gif"));
    QTRY_VERIFY(obj->status() == QSGImage::Ready);
    QTRY_VERIFY(obj->progress() == 1.0);
    QTRY_COMPARE(sourceSpy.count(), 1);
    QTRY_COMPARE(progressSpy.count(), 0);
    QTRY_COMPARE(statusSpy.count(), 0);

    // Loading remote file
    ctxt->setContextProperty("srcImage", "http://127.0.0.1:14449/stickman.gif");
    QTRY_VERIFY(obj->status() == QSGImage::Loading);
    QTRY_VERIFY(obj->progress() == 0.0);
    QTRY_VERIFY(obj->status() == QSGImage::Ready);
    QTRY_VERIFY(obj->progress() == 1.0);
    QTRY_COMPARE(sourceSpy.count(), 2);
    QTRY_VERIFY(progressSpy.count() > 1);
    QTRY_COMPARE(statusSpy.count(), 2);

    ctxt->setContextProperty("srcImage", "");
    QTRY_VERIFY(obj->status() == QSGImage::Null);
    QTRY_VERIFY(obj->progress() == 0.0);
    QTRY_COMPARE(sourceSpy.count(), 3);
    QTRY_VERIFY(progressSpy.count() > 2);
    QTRY_COMPARE(statusSpy.count(), 3);
}
开发者ID:yinyunqiao,项目名称:qtdeclarative,代码行数:46,代码来源:tst_qsganimatedimage.cpp

示例12: engineTypes

void tst_qdeclarativelistreference::engineTypes()
{
    QDeclarativeEngine engine;
    QDeclarativeComponent component(&engine, TEST_FILE("engineTypes.qml"));

    QObject *o = component.create();
    QVERIFY(o);

    QDeclarativeProperty p1(o, QLatin1String("myList"));
    QVERIFY(p1.propertyTypeCategory() == QDeclarativeProperty::Normal);

    QDeclarativeProperty p2(o, QLatin1String("myList"), engine.rootContext());
    QVERIFY(p2.propertyTypeCategory() == QDeclarativeProperty::List);
    QVariant v = p2.read();
    QVERIFY(v.userType() == qMetaTypeId<QDeclarativeListReference>());
    QDeclarativeListReference ref = qvariant_cast<QDeclarativeListReference>(v);
    QVERIFY(ref.count() == 2);
    QVERIFY(ref.listElementType());
    QVERIFY(ref.listElementType() != &QObject::staticMetaObject);

    delete o;
}
开发者ID:husninazer,项目名称:qt,代码行数:22,代码来源:tst_qdeclarativelistreference.cpp

示例13: QWidget

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
	QStringList arguments = qApp->arguments();
	Q_ASSERT_X(arguments.size() > 1, "AdiumWebView", "Application must be provide by single argument - path to theme");
	m_style.setStylePath(arguments.at(1));
	ui->comboBox->blockSignals(true);
	ui->comboBox->addItems(m_style.variants());
	ui->comboBox->setCurrentIndex(ui->comboBox->findText(m_style.activeVariant()));
	ui->comboBox->blockSignals(false);
	
	m_preview = WebKitPreviewLoader().loadPreview(SHARE_PATH + QLatin1String("Preview.plist"));
	
	{
		// QWebView
		fillPage(ui->webView->page());
//		QTimer::singleShot(1000, this, SLOT(onTimer()));
	}
	{
		// QDeclarativeView
//		QWebPage *page = new QWebPage(this);
//		qmlRegisterType<WebKitDeclarativeView>("org.adium", 0, 1, "WebChatView");
		QString baseHtml = m_style.baseTemplateForChat(m_preview->chat);
		ui->declarativeView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
		QDeclarativeEngine *engine = ui->declarativeView->engine();
		QDeclarativeContext *context = engine->rootContext();
		QVariantMap data;
		data.insert("baseHtml", baseHtml);
		data.insert("scripts", contentScripts());
		context->setContextProperty("adiumData", data);
//		context->setContextProperty("adiumData", qVariantFromValue<QObject*>(page));
//		ui->declarativeView->setSource(SHARE_PATH + QLatin1String("qml/ChatView.qml"));
//		fillPage(page);
	}
//	fillPage(ui->webView->page());
}
开发者ID:AlexeyProkhin,项目名称:qutim,代码行数:38,代码来源:widget.cpp

示例14: component

Cometd::Cometd(QObject *parent)
    : QObject(parent)
    , m_binding(new Binding(this))
{
    QDeclarativeEngine *engine = CometdPlugin::engine();
    QDeclarativeContext *rootContext = engine->rootContext();
    QDeclarativeContext *cometdContext = new QDeclarativeContext(rootContext);

    // Cometd-JavaScript depends on window.setTimeout and friends
    cometdContext->setContextProperty("timerWindow", new TimerWindow(this));

    // Allow the implementation to pass back the forward-function
    cometdContext->setContextProperty("binding", m_binding);

    cometdContext->setContextProperty("application", qApp);

    QDeclarativeComponent component(engine, QUrl("qrc:/cometd.qml"));
    QObject *implementation = component.create(cometdContext);
    cometdContext->setParent(implementation);
    implementation->setParent(this);

    QMetaObject::invokeMethod(implementation, "initialize");
}
开发者ID:torarnv,项目名称:qmlcometd,代码行数:23,代码来源:cometd.cpp

示例15: main

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    qmlRegisterType<Dict>("Vortaro", 1, 0, "Dict");
    qmlRegisterType<Word>("Vortaro", 1, 0, "Word");

    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QmlApplicationViewer viewer;
    QDeclarativeEngine *engine = viewer.engine();
    QDeclarativeContext *rootContext = engine->rootContext();

    // engine->addImportPath(QString("/opt/nokia/qtsdk/Simulator/Qt/gcc/imports"));

    Session session;
    session.load();
    rootContext->setContextObject(&session);

    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
    viewer.setSource(QUrl("qrc:///qml/main.qml"));
    // viewer.setMainQmlFile(QString("qml/main.qml"));
    viewer.showExpanded();

    return app->exec();
}
开发者ID:Execsl,项目名称:usnap,代码行数:23,代码来源:main.cpp


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