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


C++ QmlDocument::setContextProperty方法代码示例

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


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

示例1: QObject

ApplicationUI::ApplicationUI() :
        QObject()
{
    // prepare the localization
    m_pTranslator = new QTranslator(this);
    m_pLocaleHandler = new LocaleHandler(this);

    bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()));
    // This is only available in Debug builds
    Q_ASSERT(res);
    // Since the variable is not used in the app, this is added to avoid a
    // compiler warning
    Q_UNUSED(res);

    // initial load
    onSystemLanguageChanged();

    // Create scene document from main.qml asset, the parent is set
    // to ensure the document gets destroyed properly at shut down.
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    Lista * list = new Lista();
    qml->setContextProperty("_app",this);
    qml->setContextProperty("_list", list);
    // Create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    // Set created root object as the application scene
    Application::instance()->setScene(root);
}
开发者ID:compelab,项目名称:opensource,代码行数:29,代码来源:applicationui.cpp

示例2: main

/**
 * This sample applications shows how to access remote data via the FTP protocol.
 * It implements a simple browser to view the content of an FTP server and allows
 * the user to download files to the local disk.
 */
Q_DECL_EXPORT int main(int argc, char **argv)
{
    Application app(argc, argv);

    // Creates the FtpDownloader object that contains the business logic
    FtpDownloader downloader;

    // Creates the FtpItemProvider for the ListView
    FtpItemProvider itemProvider;

    // Load the UI description from main.qml
    QmlDocument *qml = QmlDocument::create("asset:///main.qml");

    // Make all the business logic objects available to the UI as context properties
    qml->setContextProperty("_model", downloader.model());
    qml->setContextProperty("_itemProvider", &itemProvider);
    qml->setContextProperty("_downloader", &downloader);
    qml->setContextProperty("_messageBox", downloader.messageBoxController());
    qml->setContextProperty("_progressDialog", downloader.progressDialogController());

    // Create the application scene
    AbstractPane *appPage = qml->createRootObject<AbstractPane>();
    Application::instance()->setScene(appPage);

    // Quit the application if 'Qt.quit()' is called in the UI
    QObject::connect(qml->documentContext()->engine(), SIGNAL(quit()), &app, SLOT(quit()));

    return Application::exec();
}
开发者ID:CodeHoarder,项目名称:Qt2Cascades-Samples,代码行数:34,代码来源:main.cpp

示例3: QObject

ApplicationUI::ApplicationUI(QObject *parent)
	: QObject(parent)
	, m_invokeManager(new InvokeManager(this))
	, m_model(new CustomGroupModel())
{
	qmlRegisterType<CustomGroupModel>("bb.mymodel", 1, 0, "CustomGroupModel");

	QString locale_string = QLocale().name();
	QString file_name = QString("WeekViewer_%1").arg(locale_string);
	if (m_pTranslator.load(file_name, "app/native/qm")) {
		QCoreApplication::instance()->installTranslator(&m_pTranslator);
	}

    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
	qml->setContextProperty("_app", this);

	ActiveCover* scene = new ActiveCover();
	Application::instance()->setCover(scene);
	qml->setContextProperty("activeFrame", scene);

    // create root object for the UI
	bb::cascades::AbstractPane *root = qml->createRootObject<AbstractPane>();
    // set created root object as a scene
	Application::instance()->setScene(root);
}
开发者ID:Jendorski,项目名称:WeekViewer,代码行数:27,代码来源:applicationui.cpp

示例4: isOnlineChanged

ApplicationUI::ApplicationUI() :
        QObject()
{
    Settings *settings;

    m_pTranslator = new QTranslator(this);
    m_pLocaleHandler = new LocaleHandler(this);

    bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()));
    Q_ASSERT(res);
    Q_UNUSED(res);

    onSystemLanguageChanged();

    settings = new Settings();

    bb::data::DataSource::registerQmlTypes();

    qmlRegisterType<SceneCover>("bb.cascades", 1, 2, "SceneCover");
    qmlRegisterType<bb::ApplicationInfo>("bb.cascades", 1, 2, "ApplicationInfo");
    qmlRegisterUncreatableType<AbstractCover>("bb.cascades", 1, 2, "AbstractCover", "An AbstractCover cannot be created.");
    qmlRegisterType<QTimer>("org.tal", 1, 0, "Timer");
    qmlRegisterType<BBMHandler>("org.tal.bbm", 1, 0, "BBMHandler");
    qmlRegisterType<bb::system::phone::Phone>("bb.system.phone", 1, 0, "Phone");

    qmlRegisterType<SopoMygga>("org.tal.sopomygga", 1, 0, "MQTT");

    QCoreApplication::setOrganizationDomain("org.tal");
    QCoreApplication::setOrganizationName("TalOrg");
    QCoreApplication::setApplicationName("Y-Radio");
    QCoreApplication::setApplicationVersion("1.0.3");

    m_netconf=new QNetworkConfigurationManager();
    res = QObject::connect(m_netconf, SIGNAL(onlineStateChanged(bool)), this, SLOT(onNetworkOnlineChanged(bool)));
    Q_ASSERT(res);

    m_isonline=m_netconf->isOnline();
    emit isOnlineChanged(m_isonline);

    m_uuid=settings->getStr("GUID", "");
    if (m_uuid.isEmpty()) {
        QUuid tmp=QUuid::createUuid();
        m_uuid=tmp.toString();
        settings->setStr("GUID", m_uuid);
        qDebug() << "NEW UUID is " << m_uuid;
    } else {
        qDebug() << "Stored UUID: " << m_uuid;
    }

    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("_yradio", this);
    qml->setContextProperty("settings", settings);
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    Application::instance()->setScene(root);
}
开发者ID:oniongarlic,项目名称:bb10-yradio,代码行数:55,代码来源:applicationui.cpp

示例5: main

//! [3]
Q_DECL_EXPORT int main(int argc, char **argv)
{
    Application app(argc, argv);

    Factorial factorial;

    // Create the state machine
    QStateMachine machine;
//! [3]

//! [4]
    // Create the 'compute' state as child of the state machine
    QState *compute = new QState(&machine);

    // Initialize the 'fac', 'x' and 'xorig' properties of the Factorial object whenever the compute state is entered
    compute->assignProperty(&factorial, "fac", 1);
    compute->assignProperty(&factorial, "x", 6);
    compute->assignProperty(&factorial, "xorig", 6);

    /**
     * Add the custom transition to the compute state.
     * Note: This transition has the compute state as source and target state.
     */
    compute->addTransition(new FactorialLoopTransition(&factorial));
//! [4]

//! [5]
    // Create a final state
    QFinalState *done = new QFinalState(&machine);

    // Add a custom transition with the 'compute' state as source state and the 'done' state as target state
    FactorialDoneTransition *doneTransition = new FactorialDoneTransition(&factorial);
    doneTransition->setTargetState(done);
    compute->addTransition(doneTransition);
//! [5]

//! [6]
    // Set the 'compute' state as initial state of the state machine
    machine.setInitialState(compute);

    // Load the UI description from main.qml
    QmlDocument *qml = QmlDocument::create("asset:///main.qml");

    // Make the Factorial and StateMachine object available to the UI as context properties
    qml->setContextProperty("_factorial", &factorial);
    qml->setContextProperty("_machine", &machine);

    // Create the application scene
    AbstractPane *appPage = qml->createRootObject<AbstractPane>();
    Application::instance()->setScene(appPage);

    return Application::exec();
}
开发者ID:CodeHoarder,项目名称:Qt2Cascades-Samples,代码行数:54,代码来源:main.cpp

示例6: CustomControl

HomeLayout::HomeLayout(User *homeUser) :
                CustomControl()
{
	user = homeUser;

	QmlDocument *qml = QmlDocument::create("asset:///twitterhome.qml");
	qml->setContextProperty("homeView", this);
	qml->setContextProperty("twitterUser", user);

	Control *root = qml->createRootObject<Control>();
	bb::cascades::CustomControl::setRoot(root);
}
开发者ID:Mouzmip,项目名称:twitter-bb10,代码行数:12,代码来源:HomeLayout.cpp

示例7: QObject

RundGangApp::RundGangApp(bb::cascades::Application *app) :
        QObject(app)
{
    // Localization: Make the initial call to set up the initial application language and
    // connect to the LocaleHandlers systemLanguaged change signal, this will
    // tell the application when it is time to load a new set of language strings.
    mTranslator = new QTranslator(this);
    mLocaleHandler = new LocaleHandler(this);
    onSystemLanguageChanged();
    bool connectResult = connect(mLocaleHandler, SIGNAL(systemLanguageChanged()), SLOT(onSystemLanguageChanged()));
    Q_ASSERT(connectResult);
    Q_UNUSED(connectResult);

    // Register objects for assisting the Control of the Photo feedback page.
    qmlRegisterType<PhotoController>("com.rundgang", 1, 0, "PhotosController");
    qmlRegisterType<AudioController>("com.rundgang", 1, 0, "AudioController");
    qmlRegisterType<CustomSqlDataSource>("com.rundgang", 1, 0, "CustomSqlDataSource");
    qmlRegisterType<EmailController>("com.rundgang", 1, 0, "EmailController");

    // Registering picker types and Contact Picker helper object,
    // so that it can be used in QML.
    qmlRegisterType<ContactPicker>("bb.cascades.pickers", 1, 0, "ContactPicker");
    qmlRegisterUncreatableType<ContactSelectionMode>("bb.cascades.pickers", 1, 0,
            "ContactSelectionMode", "Non creatable enum type");

    // Create scene document from main.qml asset, the parent is set
    // to ensure the document gets destroyed properly at shut down.
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    // Create the GlobalSettings object that holds application wide settings.
    GlobalSettings *globalSettings = new GlobalSettings(this);
    qml->setContextProperty("_appSettings", globalSettings);

    // Make the application object accessible from QML.
    qml->setContextProperty("_app", this);

    // Set the stored visual style of the application.
    app->themeSupport()->setVisualStyle(globalSettings->visualStyle());

    // Create root object for the UI.
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    // Set created root object as the application scene.
    app->setScene(root);

    // Add an application cover, shown when the app is running in minimized mode.
    addApplicationCover();
}
开发者ID:26filip,项目名称:Cascades-Samples,代码行数:48,代码来源:rundgangapp.cpp

示例8: setNumMoves

KakelApp::KakelApp()
{

  // Create and Load the QMLDocument, using build patterns.
  QmlDocument *qml = QmlDocument::create("asset:///main.qml");

  if (!qml->hasErrors()) {

    setNumMoves(0);
    mNumTiles = 4;

    // Set the context property we want to use from inside the QML file. Functions exposed
    // via Q_INVOKABLE will be found with the property and the name of the function.
    qml->setContextProperty("kakel", this);

    // The application Page is created from the QML file.
    mAppPage = qml->createRootObject<Page>();

    findPlayAreaAndInitialize(mAppPage);

    if (mAppPage) {
      // Finally the main scene for the application is set to the Page.
      Application::instance()->setScene(mAppPage);
    }
  }
}
开发者ID:Angtrim,项目名称:Cascades-Samples,代码行数:26,代码来源:kakelapp.cpp

示例9: QObject

RocknRoll::RocknRoll(bb::cascades::Application *app)
: QObject(app)
{
    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    AlbumsDataModel *p1DataModel = new AlbumsDataModel(this);
    SongsDataModel *p2DataModel = new SongsDataModel(this);
    qml->setContextProperty("_model1", p1DataModel);
    qml->setContextProperty("_model2", p2DataModel);

    qmlRegisterType<QTimer>("QTimer", 1, 0, "QTimer");
    qmlRegisterType<SceneCover>("bb.cascades", 1, 0, "SceneCover");
    qmlRegisterUncreatableType<AbstractCover>("bb.cascades", 1, 0, "AbstractCover", "An AbstractCover cannot be created.");

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    // set created root object as a scene
    app->setScene(root);

    startNetworkManager();
    //parseJSON();
}
开发者ID:sanjayasl,项目名称:RocknRoll,代码行数:25,代码来源:RocknRoll.cpp

示例10: QObject

MalcomLibBb10::MalcomLibBb10(bb::cascades::Application *app)
: QObject(app)
{
    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    connect(app, SIGNAL(fullscreen()), this, SLOT(onFullscreen()));
    connect(app, SIGNAL(thumbnail()), this, SLOT(onThumbnail()));

    root = qml->createRootObject<AbstractPane>();

    MalcomLib::Instance() -> initMalcom(uuidMalcom, secretKeyMalcom);

    QVariantList tags;
    tags << "tag1" << "tag2" << "tag3" << "tag4";

    MalcomLib::Instance() -> setTags(tags);

    QDeclarativePropertyMap malcom;
    malcom.insert("uuid", uuidMalcom);
    malcom.insert("secretKey", secretKeyMalcom);

    qml->setContextProperty("malcom", &malcom);

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    // set created root object as a scene
    app->setScene(root);
}
开发者ID:MyMalcom,项目名称:malcom-lib-bb10,代码行数:30,代码来源:MalcomLibBb10.cpp

示例11: initForeignWindow

HelloForeignWindowApp::HelloForeignWindowApp()
{
    mTvOn = false;
    mTvInitialized = false;

    // Create a QML document and load the main UI QML file, using build patterns.
    QmlDocument *qml = QmlDocument::create("asset:///helloforeignwindow.qml");

    if (!qml->hasErrors()) {

        // Set the context property we want to use from inside the QML document. Functions exposed
        // via Q_INVOKABLE will be found with this property and the name of the function.
        qml->setContextProperty("foreignWindowApp", this);

        // The application Page is created from QML.
        mAppPage = qml->createRootObject<Page>();

        if (mAppPage) {

            Application::instance()->setScene(mAppPage);

            // Initialize the foreign window.
            initForeignWindow();

            // Start the thread in which we render to the custom window.
            start();
        }
    }
}
开发者ID:Angtrim,项目名称:Cascades-Samples,代码行数:29,代码来源:helloforeignwindowapp.cpp

示例12: connect

ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
		QObject(app) {
	// create scene document from main.qml asset
	// set parent to created document to ensure it exists for the whole application lifetime
	QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

	// Expose this class to QML such that our Q_INVOKABLE methods defined in applicationui.hpp
	// can be called from our QML classes.
	qml->setContextProperty("cpp", this);

	// create root object for the UI
	AbstractPane *root = qml->createRootObject<AbstractPane>();
	// set created root object as a scene
	app->setScene(root);

	// The code from here down to "void ApplicationUI::logEvent" is used to determine the device
	// location and log the result to the Flurry server. Any errors in the process will also be
	// logged
	QGeoPositionInfoSource *source =
			QGeoPositionInfoSource::createDefaultSource(this);

	if (source) {
		bool positionUpdatedConnected = connect(source,
				SIGNAL(positionUpdated (const QGeoPositionInfo &)), this,
				SLOT(positionUpdated (const QGeoPositionInfo &)));

		if (positionUpdatedConnected) {
			source->requestUpdate();
		} else {
			qDebug() << "positionUpdated connection failed";
			Flurry::Analytics::LogError("positionUpdated connection failed");
		}
	} else {
开发者ID:26filip,项目名称:Cascades-Community-Samples,代码行数:33,代码来源:applicationui.cpp

示例13: QObject

RegistrationHandler::RegistrationHandler(const QUuid &uuid, QObject *parent)
    : QObject(parent)
    , m_context(uuid)
    , m_isAllowed(false)
    , m_progress(BbmRegistrationProgress::NotStarted)
    , m_temporaryError(false)
    , m_statusMessage(tr("Please wait while the application connects to BBM."))
{
    QmlDocument* qml = QmlDocument::create("asset:///registration.qml")
                       .parent(this);
    qml->setContextProperty("_registrationHandler", this);
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    if (uuid.isNull()) {
    	SystemDialog *uuidDialog = new SystemDialog("OK");
    	uuidDialog->setTitle("UUID Error");
        uuidDialog->setBody("Invalid/Empty UUID, please set correctly in main.cpp");
        connect(uuidDialog, SIGNAL(finished(bb::system::SystemUiResult::Type)), this, SLOT(dialogFinished(bb::system::SystemUiResult::Type)));
        uuidDialog->show();
        return;
    }
    connect(&m_context,
            SIGNAL(registrationStateUpdated(
                   bb::platform::bbm::RegistrationState::Type)),
            this,
            SLOT(processRegistrationStatus(
                 bb::platform::bbm::RegistrationState::Type)));

    if (m_context.isAccessAllowed()){ // jika sudah teregister langsung ke main app
    	qDebug() << "access allowed";
    	finishRegistration();
    }else{ // jika belum, tampilkan halaman registrasi ini.
        Application::instance()->setScene(root);
    }
}
开发者ID:ferdirn,项目名称:Quran,代码行数:35,代码来源:RegistrationHandler.cpp

示例14: start

HelloForeignWindowApp::HelloForeignWindowApp()
{
    mTvOn = false;
    mTvInitialized = false;

    // Here we create a QMLDocument and load the main UI QML file.
    QmlDocument *qml = QmlDocument::create().load("helloforeignwindow.qml");

    if (!qml->hasErrors()) {

        // Set a context property for the QML to the application object, so that we
        // can call invokable functions in the app from QML.
        qml->setContextProperty("foreignWindowApp", this);

        // The application Page is created from QML.
        mAppPage = qml->createRootNode<Page>();

        if (mAppPage) {

            Application::setScene(mAppPage);

            // Start the thread in which we render to the custom window.
            start();
        }
    }
}
开发者ID:PaulBernhardt,项目名称:Cascades-Samples,代码行数:26,代码来源:helloforeignwindowapp.cpp

示例15: QObject

//! [0]
App::App(QObject *parent)
    : QObject(parent)
    , m_invokeManager(new InvokeManager(this))
    , m_backButtonVisible(false)
{
    // Listen to incoming invocation requests
    connect(m_invokeManager, SIGNAL(invoked(const bb::system::InvokeRequest&)), this, SLOT(handleInvoke(const bb::system::InvokeRequest&)));
    connect(m_invokeManager, SIGNAL(cardResizeRequested(const bb::system::CardResizeMessage&)), this, SLOT(resized(const bb::system::CardResizeMessage&)));
    connect(m_invokeManager, SIGNAL(cardPooled(const bb::system::CardDoneMessage&)), this, SLOT(pooled(const bb::system::CardDoneMessage&)));

    // Initialize properties with default values
    switch (m_invokeManager->startupMode()) {
        case ApplicationStartupMode::LaunchApplication:
            m_startupMode = tr("Launch");
            break;
        case ApplicationStartupMode::InvokeApplication:
            m_startupMode = tr("Invoke");
            break;
        case ApplicationStartupMode::InvokeCard:
            m_startupMode = tr("Card");
            break;
    }

    m_source = m_target = m_action = m_mimeType = m_uri = m_data = m_status = tr("--");
    m_title = tr("InvokeClient");

    // Create the UI
    QmlDocument *qml = QmlDocument::create("asset:///main.qml");
    qml->setContextProperty("_app", this);
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    Application::instance()->setScene(root);
}
开发者ID:Ataya09,项目名称:Cascades-Samples,代码行数:33,代码来源:app.cpp


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