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


C++ QDeclarativeContext类代码示例

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


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

示例1: QDeclarativeContext

void AlternatingListItem::setup(const QString& qmlFile) {
	QmlDocument* document = QmlDocument::create(qmlFile);
	QDeclarativeContext *derivedContext = new QDeclarativeContext(
			document->documentContext(), this);
	derivedContext->setContextProperty("_item", this);

	setRoot(document->createRootObject<Control>(derivedContext));
}
开发者ID:BBKeeper,项目名称:Cascades-Community-Samples,代码行数:8,代码来源:alternatinglistitem.cpp

示例2: Q_Q

void QDeclarativeLoaderPrivate::_q_sourceLoaded()
{
    Q_Q(QDeclarativeLoader);

    if (component) {
        if (!component->errors().isEmpty()) {
            QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors());
            emit q->sourceChanged();
            emit q->statusChanged();
            emit q->progressChanged();
            return;
        }

        QDeclarativeContext *creationContext = component->creationContext();
        if (!creationContext) creationContext = qmlContext(q);
        QDeclarativeContext *ctxt = new QDeclarativeContext(creationContext);
        ctxt->setContextObject(q);

        QDeclarativeGuard<QDeclarativeComponent> c = component;
        QObject *obj = component->beginCreate(ctxt);
        if (component != c) {
            // component->create could trigger a change in source that causes
            // component to be set to something else. In that case we just
            // need to cleanup.
            if (c)
                c->completeCreate();
            delete obj;
            delete ctxt;
            return;
        }
        if (obj) {
            item = qobject_cast<QGraphicsObject *>(obj);
            if (item) {
                QDeclarative_setParent_noEvent(ctxt, obj);
                QDeclarative_setParent_noEvent(item, q);
                item->setParentItem(q);
//                item->setFocus(true);
                initResize();
            } else {
                qmlInfo(q) << QDeclarativeLoader::tr("Loader does not support loading non-visual elements.");
                delete obj;
                delete ctxt;
            }
        } else {
            if (!component->errors().isEmpty())
                QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors());
            delete obj;
            delete ctxt;
            source = QUrl();
        }
        component->completeCreate();
        emit q->sourceChanged();
        emit q->statusChanged();
        emit q->progressChanged();
        emit q->itemChanged();
        emit q->loaded();
    }
}
开发者ID:wpbest,项目名称:copperspice,代码行数:58,代码来源:qdeclarativeloader.cpp

示例3: statusChanged

//! [3]
void Loader::sourceLoaded()
{
    if (m_component) { // Sanity check

        /**
         * If an error occured during loading, just emit the change notification
         * signals, the 'status' property will reflect that error state.
         */
        if (!m_component->errors().isEmpty()) {
            emit statusChanged();
            emit progressChanged();
            emit sourceChanged();
            emit controlChanged();
            return;
        }

        // Get the declarative context of the declarative component
        QDeclarativeContext *creationContext = m_component->creationContext();

        // If it has not been set, use the declarative context of the Loader element as fallback
        if (!creationContext)
            creationContext = QDeclarativeEngine::contextForObject(this);

        // Create a new child context that will be used as declarative context for the Cascades object
        QDeclarativeContext *ctxt = new QDeclarativeContext(creationContext);
        ctxt->setContextObject(this);

        // Load the Cascades object
        QObject *object = m_component->create(ctxt);
        if (object) {
            m_control = qobject_cast<bb::cascades::Control*>(object);
            if (m_control) {
                // If the loaded Cascades object is a Control, we use it as root element for the Loader and make it visible
                setRoot(m_control);
                setVisible(true);
            } else {
                // Otherwise report an error
                qmlInfo(this) << tr("Loader does not support loading non-visual elements.");
                delete object;
                delete ctxt;
            }
        } else {
            // Cleanup if the loading failed
            delete object;
            delete ctxt;
            m_source = QUrl();
        }

        emit sourceChanged();
        emit statusChanged();
        emit progressChanged();
        emit controlChanged();
        emit loaded();
    }
}
开发者ID:13natty,项目名称:Cascades-Samples,代码行数:56,代码来源:Loader.cpp

示例4: _initViewer

void MeeTv::_initViewer()
{
    QDeclarativeContext *context = m_viewer.rootContext();
    context->setContextProperty("dvrEntriesModel", m_dvrEntriesModel);
    context->setContextProperty("htsp", m_htsp);
    context->setContextProperty("meetv", this);
    context->setContextProperty("settings", m_settings);
    context->setContextProperty("tagModel", m_tagModel);

    m_viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    m_viewer.setMainQmlFile(QLatin1String("qml/MeeTV/main.qml"));
}
开发者ID:RobertMe,项目名称:MeeTV,代码行数:12,代码来源:meetv.cpp

示例5: main

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QApplication *app;
#ifdef QT_SIMULATOR
    app = new QApplication(argc, argv);
#else
    app = MDeclarativeCache::qApplication(argc, argv);
#endif
    app->setApplicationName("Butaca");
    app->setOrganizationDomain("com.simonpena");
    app->setOrganizationName("simonpena");

    // Assume that strings in source files are UTF-8
    QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));

    QString locale(QLocale::system().name());
    QTranslator translator;

    if (translator.load("l10n/butaca." + locale, ":/")) {
        app->installTranslator(&translator);
    } else {
        translator.load("l10n/butaca.en.qm", ":/");
        app->installTranslator(&translator);
    }

    QDeclarativeView *view;
#ifdef QT_SIMULATOR
    view = new QDeclarativeView();
#else
    view = MDeclarativeCache::qDeclarativeView();
#endif

    view->engine()->setOfflineStoragePath(
                QDesktopServices::storageLocation(QDesktopServices::DataLocation));

    QDeclarativeContext *context = view->rootContext();

    // The Movie Database uses "-" as the divider between language and country code
    context->setContextProperty("appLocale", locale.left(locale.indexOf("_")));
    Controller *controller = new Controller(context);

    view->engine()->setNetworkAccessManagerFactory(new CustomNetworkAccessManagerFactory);
    view->setSource(QUrl("qrc:/qml/main.qml"));
    view->showFullScreen();

    int result = app->exec();

    delete controller;
    delete view;
    delete app;

    return result;
}
开发者ID:chegestar,项目名称:butaca,代码行数:53,代码来源:main.cpp

示例6: 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

示例7: qputenv

void tst_QDeclarativeDebug::initTestCase()
{
    qRegisterMetaType<QDeclarativeDebugWatch::State>();

    QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 3768...");
    qputenv("QML_DEBUG_SERVER_PORT", "3768");
    m_engine = new QDeclarativeEngine(this);

    QList<QByteArray> qml;
    qml << "import Qt 4.7\n"
            "Item {"
                "width: 10; height: 20; scale: blueRect.scale;"
                "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }"
                "Text { color: blueRect.color; }"
                "MouseArea {"
                    "onEntered: { console.log('hello') }"
                "}"
            "}";

    // add second component to test multiple root contexts
    qml << "import Qt 4.7\n"
            "Item {}";

    // and a third to test methods
    qml << "import Qt 4.7\n"
            "Item {"
                "function myMethodNoArgs() { return 3; }\n"
                "function myMethod(a) { return a + 9; }\n"
                "function myMethodIndirect() { myMethod(3); }\n"
            "}";

    for (int i=0; i<qml.count(); i++) {
        QDeclarativeComponent component(m_engine);
        component.setData(qml[i], QUrl::fromLocalFile(""));
        Q_ASSERT(component.isReady());  // fails if bad syntax
        m_components << qobject_cast<QDeclarativeItem*>(component.create());
    }
    m_rootItem = qobject_cast<QDeclarativeItem*>(m_components.first());

    // add an extra context to test for multiple contexts
    QDeclarativeContext *context = new QDeclarativeContext(m_engine->rootContext(), this);
    context->setObjectName("tst_QDeclarativeDebug_childContext");

    m_conn = new QDeclarativeDebugConnection(this);
    m_conn->connectToHost("127.0.0.1", 3768);

    QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established");
    bool ok = m_conn->waitForConnected();
    Q_ASSERT(ok);
    QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient());

    m_dbg = new QDeclarativeEngineDebug(m_conn, this);
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.vendor,代码行数:53,代码来源:tst_qdeclarativedebug.cpp

示例8: rootContext

void
ProcessMethodView::OnCreate( const adportable::Configuration& config )
{
    *pConfig_ = config;

    std::wstring xml = config.xml();

    pugi::xml_document dom;
    pugi::xml_parse_result result;

    if ( ! ( result = dom.load( pugi::as_utf8( xml ).c_str() ) ) )
        return;

    qmlRegisterType< CentroidMethodModel >( "com.scienceliaison.qml", 1, 0, "CentroidModel" );
	// qmlRegisterType< IsotopeMethodModel > ( "com.scienceliaison.qml", 1, 0, "IsotopeModel" );
    qmlRegisterType< ElementalCompModel > ( "com.scienceliaison.qml", 1, 0, "ElementalCompModel" );
	// qmlRegisterType< MSCalibrateModel > ( "com.scienceliaison.qml", 1, 0, "MSCalibrateModel" );

    QDeclarativeContext * ctx = rootContext();
    ctx->setContextProperty( "configXML", qtwrapper::qstring::copy( xml ) );
    ctx->setContextProperty( "centroidModel", pCentroidModel_.get() );
	// ctx->setContextProperty( "isotopeModel", pIsotopeModel_.get() );
    ctx->setContextProperty( "elementalCompModel", pElementalCompModel_.get() );
	// ctx->setContextProperty( "msCalibrateModel", pMSCalibrateModel_.get() );
    setResizeMode( QDeclarativeView::SizeRootObjectToView );

#if defined DEBUG && 0
    do {
      std::ofstream of( "/Users/thondo/src/qtplatz/config.xml" );
      dom.save( of );
    } while(0);
#endif

    QString qmlpath;
#ifdef Q_OS_MAC
    qmlpath = QCoreApplication::applicationDirPath() + "/../Resources";
#else
    qmlpath = QCoreApplication::applicationDirPath() + "/../share";
#endif

    // engine()->addImportPath( QCoreApplication::applicationDirPath() + "/../imports" );
    // QML_IMPORT_PATH

    pugi::xpath_node node = dom.select_single_node( "//Component[@type='qml']" );
    if ( node ) {
        QString source = qmlpath + node.node().attribute( "QUrl" ).value();
        setSource( QUrl::fromLocalFile( source ) );

        QList< QDeclarativeError > errors = this->errors();
        for ( QList< QDeclarativeError >::const_iterator it = errors.begin(); it != errors.end(); ++it )
            QMessageBox::warning( this, "QDeclarativeError", it->toString() + " file: " + source );
    }
}
开发者ID:hermixy,项目名称:qtplatz,代码行数:53,代码来源:processmethodview.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: QFrame

IconView::IconView(QAbstractItemModel *model, QWidget *parent) :
    QFrame(parent), m_model(model)
{
    QDeclarativeView *view = new QDeclarativeView(this);
    QDeclarativeContext *ctxt = view->rootContext();
    ctxt->setContextProperty("orderModel", m_model);
    ctxt->setContextProperty("sizeData", this);
    view->setSource(QUrl("qrc:IconView.qml"));
    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->setMargin(0);
    mainLayout->addWidget(view);
    setLayout(mainLayout);
}
开发者ID:crysislinux,项目名称:openmenus,代码行数:13,代码来源:iconview.cpp

示例11: main

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

    // Load settings
    QSettings settings;
    settings.setValue("dbtype", "QSQLITE");
    settings.setValue("dbname", "/tmp/testdb.sqlite3");

    // Translator
    QString translationfile = QString("qtmc_nl");
    QTranslator translator;
    if (!translator.load(translationfile) &&
            !translator.load(translationfile,
                             app.applicationDirPath() +  "../lib/qtmc/translations/")) {
        qWarning() << "Failed to load translation file";
    }
    app.installTranslator(&translator);

    // Open database
    QSqlDatabase db = QSqlDatabase::addDatabase(settings.value("dbtype").toString());
    db.setDatabaseName(settings.value("dbname").toString());
    //db.setDatabaseName(":memory:");

    // Check if database is open
    if (!db.open()) {
        qWarning() << app.tr("Cannot open database") << settings.value("dbname");
        return 1;
    }

    // Create mediadb
    MediaDB *mediadb = new MediaDB();
    qDebug() << app.tr("QtMC version") << QString(QTMC_VERSION);
    qDebug() << app.tr("MediaDB version") << mediadb->version();

    // Create qml-view and connect quit-signal
    QDeclarativeView *view = new QDeclarativeView;
    QObject::connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));

    // Expose c++ object to qml
    QDeclarativeContext *ctxt = view->rootContext();
    ctxt->setContextProperty("MediaDB", mediadb);
    ctxt->setContextProperty("Settings", &settings);

    // Run view
    view->setSource(QUrl(app.applicationDirPath() + "/../lib/qtmc/qml/QtMC.qml"));
    view->show();
    //view->showFullScreen();

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

示例12: main

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));

    QmlApplicationViewer viewer;
    QDeclarativeContext *ctxt = viewer.rootContext();
    ctxt->setContextProperty("KipptConnector", new KipptConnector());

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

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

示例13: main

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

    QDeclarativeView view;
    QDeclarativeContext *context = view.rootContext();
    context->setContextProperty("backgroundColor",
                                QColor(Qt::yellow));

    view.setSource(QUrl::fromLocalFile("main.qml"));
    view.show();

    return app.exec();
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.vendor,代码行数:14,代码来源:main.cpp

示例14: qDebug

QGraphicsItem *FolderPlugin::item()
{
   if (mFrameParentitem == NULL) {
       mFrameParentitem = new PlexyDesk::QmlDesktopWidget(QRectF(0.0, 0.0, 400.0, 400.0));
       QDeclarativeContext *context = mFrameParentitem->engine()->rootContext();
       const QString qmlData = mThemePack->hiddenQmlWidgets(QLatin1String("folderview"));

       qDebug() << Q_FUNC_INFO << qmlData;
       context->setContextProperty("DirSource", this);
       mFrameParentitem->setSourceUrl (QUrl(qmlData));
   }

   return mFrameParentitem;
}
开发者ID:jdarnold,项目名称:plexydesk,代码行数:14,代码来源:folderplugin.cpp

示例15: main

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());

    shortcutMaker sm;
    QDeclarativeContext *ctxt = viewer->rootContext();
    ctxt->setContextProperty("sm", &sm);

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

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


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