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


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

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


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

示例1: main

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QGuiApplication::setApplicationDisplayName(QCoreApplication::translate("main",
                                                                           "QtWebView Example"));
#ifdef QT_WEBVIEW_WEBENGINE_BACKEND
    QtWebEngine::initialize();
#endif // QT_WEBVIEW_WEBENGINE_BACKEND
    QCommandLineParser parser;
    QCoreApplication::setApplicationVersion(QT_VERSION_STR);
    parser.setApplicationDescription(QGuiApplication::applicationDisplayName());
    parser.addHelpOption();
    parser.addVersionOption();
    parser.addPositionalArgument("url", "The initial URL to open.");
    parser.process(app);
    const QString initialUrl = parser.positionalArguments().isEmpty() ?
        QStringLiteral("qt.io") : parser.positionalArguments().first();

    QQmlApplicationEngine engine;
    QQmlContext *context = engine.rootContext();
    context->setContextProperty(QStringLiteral("utils"), new Utils(&engine));
    context->setContextProperty(QStringLiteral("initialUrl"),
                                Utils::fromUserInput(initialUrl));
    QRect geometry = QGuiApplication::primaryScreen()->availableGeometry();
    if (!QGuiApplication::styleHints()->showIsFullScreen()) {
        const QSize size = geometry.size() * 4 / 5;
        const QSize offset = (geometry.size() - size) / 2;
        const QPoint pos = geometry.topLeft() + QPoint(offset.width(), offset.height());
        geometry = QRect(pos, size);
    }
    context->setContextProperty(QStringLiteral("initialX"), geometry.x());
    context->setContextProperty(QStringLiteral("initialY"), geometry.y());
    context->setContextProperty(QStringLiteral("initialWidth"), geometry.width());
    context->setContextProperty(QStringLiteral("initialHeight"), geometry.height());
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

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

示例2: main

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

	qRegisterMetaType<TreeViewModel>("TreeViewModel");
	qRegisterMetaType<ConfigNode>	("ConfigNode");
	qRegisterMetaType<UndoManager>	("UndoManager");
	qRegisterMetaType<GUIBackend>	("GUIBackend");
	qRegisterMetaType<GUISettings>	("GUISettings");
	qmlRegisterType<DataContainer>	("org.libelektra.qtgui", 1, 0, "DataContainer");

	QString locale = QLocale::system().name();

	QTranslator translator;
	translator.load(QString(":/qml/i18n/lang_") + locale + QString(".qm"));
	app.installTranslator(&translator);

	QQmlApplicationEngine engine;
	QQmlContext* ctxt = engine.rootContext();

	UndoManager manager;
	GUIBackend	backend;
	GUISettings settings;
	TreeViewModel treeModel;

	engine.setObjectOwnership(&treeModel, QQmlApplicationEngine::CppOwnership);

	ctxt->setContextProperty("undoManager", &manager);
	ctxt->setContextProperty("externTreeModel", &treeModel);
	ctxt->setContextProperty("guiBackend", &backend);
	ctxt->setContextProperty("guiSettings", &settings);

	treeModel.populateModel();

	engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));

	return app.exec();
}
开发者ID:tom-wa,项目名称:libelektra,代码行数:38,代码来源:main.cpp

示例3: main

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

    QQmlApplicationEngine engine;

    QQmlContext* context = engine.rootContext();

    QString currPath = QDir::currentPath();
    context->setContextProperty("currentPath", currPath);

    QScreen *screen = QApplication::screens().at(0);
    int width = screen->availableSize().width();
    context->setContextProperty("availableWidth", width);
    int height = screen->availableSize().height();
    context->setContextProperty("availableHeight", height);

    MainController* mainController = new MainController();
    context->setContextProperty("mainController", mainController);

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
}
开发者ID:Slesa,项目名称:Trinity,代码行数:23,代码来源:main.cpp

示例4: main

int main(int argc, char *argv[])
{
#ifdef Q_OS_LINUX
    // When using QAudioOutput on linux/ALSA, we need to
    // block SIGIO on all threads except the audio thread
    sigset_t set;
    sigemptyset(&set);
    sigaddset(&set, SIGIO);
    pthread_sigmask(SIG_BLOCK, &set, nullptr);
#endif

    qSetMessagePattern("[%{if-debug}D%{endif}%{if-warning}W%{endif}"
                       "%{if-critical}C%{endif}%{if-fatal}F%{endif}]"
                       "%{if-category} [%{category}]:%{endif} %{message}");

    QGuiApplication a(argc, argv);
    a.setApplicationName("Phoenix");
    a.setApplicationVersion(PHOENIX_VERSION);
    a.setOrganizationName("Phoenix");
//    a.setOrganizationDomain("phoenix-emu.org");
    QSettings settings;


    qmlRegisterType<PhoenixWindow>("phoenix.window", 1, 0, "PhoenixWindow");
    qmlRegisterType<CachedImage>("phoenix.image", 1, 0, "CachedImage");
    qmlRegisterType<VideoItem>("phoenix.video", 1, 0, "VideoItem");
    qmlRegisterType<GameLibraryModel>();
    qmlRegisterType<PhoenixLibrary>("phoenix.library", 1, 0, "PhoenixLibrary");
    qmlRegisterType<InputDeviceMapping>();
    qmlRegisterType<InputDevice>();
    qRegisterMetaType<retro_device_id>("retro_device_id");
    qRegisterMetaType<int16_t>("int16_t");
    qRegisterMetaType<InputDeviceEvent *>();

    QQmlApplicationEngine engine;
    // first, set the context properties
    QQmlContext *rctx = engine.rootContext();
    rctx->setContextProperty("inputmanager", &input_manager);

    // then, load qml and display the window
    engine.load(QUrl("qrc:/qml/main.qml"));
    QObject *topLevel = engine.rootObjects().value(0);
    PhoenixWindow *window = qobject_cast<PhoenixWindow *>(topLevel);
    window->setCacheDirectory(engine.offlineStoragePath() + "/");
    window->show();

    input_manager.scanDevices();

    return a.exec();
}
开发者ID:juliendn,项目名称:Phoenix,代码行数:50,代码来源:main.cpp

示例5: main

int main(int argc, char *argv[])
{
    QGuiApplication *app = SailfishApp::application(argc, argv);
    QQuickView *view = SailfishApp::createView();
    QQmlContext *context = view->rootContext();

    // This will hook into the view and render OpenGL on top of it
    ShaderToyGLView shaderToyView(view);
    context->setContextProperty("shaderToy", &shaderToyView);
    view->setSource(SailfishApp::pathTo("qml/shadertoy.qml"));
    view->show();

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

示例6: setQml

void Controller::setQml(const QString &qmlfile, const QString &screenName)
{
    QQmlContext *qmlcontext = qmlviewer->rootContext();
    QString file = qmlfile;
    QString qmlfullpath = file.prepend(QML_PATH);
    const QUrl qmlurl(qmlfullpath);

    if(screenName != "settings")
        screenSettings->stopPreview();

    qmlcontext->setContextProperty("activeScreen", screenName);

    QMetaObject::invokeMethod(qmlviewer, "setSource", Qt::QueuedConnection, Q_ARG(QUrl, qmlurl));
}
开发者ID:lmedeiros,项目名称:softphone,代码行数:14,代码来源:controller.cpp

示例7: main

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

    DataMethods methodsStopWatch("stopwatchResults.txt");
    DataMethods methodsCountDown("countdownResults.txt");
    //load stored results from .txt files to listViews of stopWatch and countDown sections
    methodsStopWatch.loadData();
    methodsCountDown.loadData();

    QQmlContext *ctxt = engine.rootContext();
    //give access to saved models in .txt to stopWatch and countDown sections in QML ( used upon new sesion of program)
    ctxt->setContextProperty("myStopWatchModel",QVariant::fromValue(&methodsStopWatch));
    ctxt->setContextProperty("myCountDownModel",QVariant::fromValue(&methodsCountDown));

    //give option to manipulate ( add results and save/clear) .txt file with methods inside DataMethods
    ctxt->setContextProperty("saveStopWatchModel",QVariant::fromValue(&methodsStopWatch));
    ctxt->setContextProperty("saveCountDownModel",QVariant::fromValue(&methodsCountDown));

    engine.load(QUrl(QStringLiteral("qrc:/mainSW.qml")));
    return app.exec();
}
开发者ID:GregoryIwanek,项目名称:Stopwatch-CountDown,代码行数:23,代码来源:main.cpp

示例8: main

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

    QQmlApplicationEngine engine;

    Buzzer theBuzzer;

    QQmlContext *ctxt = engine.rootContext();
    ctxt->setContextProperty("Buzzer", &theBuzzer);

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

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

示例9: main

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;

    Receiver receiver;

    QQmlContext* ctx = engine.rootContext();
    ctx->setContextProperty("receiver", &receiver);
    engine.load(QUrl(QStringLiteral("qrc:///main.qml")));

    receiver.sendToQml(43);

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

示例10: main

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

    QQmlApplicationEngine engine;

    UdpSeret * udpSeret = new UdpSeret(&app);
    udpExtraDataCACC * udpXDataCACC = new udpExtraDataCACC(&app);
    UDPSender * udpSender = new UDPSender(&app);
    UDPVehicle * udpVehicle=new UDPVehicle(&app);


    QQmlContext * rc = engine.rootContext();
    rc->setContextProperty("udpSeret", udpSeret);
    rc->setContextProperty("udpXDataCACC", udpXDataCACC);
    rc->setContextProperty("udpSender",udpSender);
    rc->setContextProperty("udpVehicle",udpVehicle);

    qmlRegisterType<FileIO, 1>("FileIO", 1, 0, "FileIO");

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}
开发者ID:jspring,项目名称:rfs-volvo_cacc,代码行数:24,代码来源:main.cpp

示例11: main

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

	QApplication app(argc, argv);

	QQmlApplicationEngine engine;
	QQmlContext *root = engine.rootContext();
	DataBase *db = new DataBase();

	root->setContextProperty("DataBase", db);

	engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

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

示例12: contextSetProperty

void contextSetProperty(QQmlContext_ *context, QString_ *name, DataValue *value)
{
    const QString *qname = reinterpret_cast<QString *>(name);
    QQmlContext *qcontext = reinterpret_cast<QQmlContext *>(context);

    QVariant var;
    unpackDataValue(value, &var);

    // Give qvalue an engine reference if it doesn't yet have one .
    QObject *obj = var.value<QObject *>();
    if (obj && !qmlEngine(obj)) {
        QQmlEngine::setContextForObject(obj, qcontext);
    }

    qcontext->setContextProperty(*qname, var);
}
开发者ID:chai2010,项目名称:qml,代码行数:16,代码来源:goqml.cpp

示例13: removeEffect

void EffectsManager::removeEffect(int i)
{
    qDebug() << "begin remove effect:"<<i;
    QQmlContext *ctxt = view.rootContext();
    if (i<0 || i>=dataListLabels.length() || i>=dataListValues.length())
    {
        qDebug() << "end remove effect";
        return;

    }
    dataListValues.removeAt(i);
    qDebug() << "1";
    dataListLabels.removeAt(i);
    qDebug() << "2";
    ctxt->setContextProperty("myModel",dataListLabels);
    qDebug() << "end remove effect";

}
开发者ID:roma2341,项目名称:OpenBoard,代码行数:18,代码来源:effectscontroll.cpp

示例14: main

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

    qmlRegisterType<ChessController>("Chess", 1, 0, "ChessController");

    ChessController chessController;

    QQmlApplicationEngine engine;
    QQmlContext *qmlcontext = engine.rootContext();
    if (!qmlcontext) {
        qWarning() << "Cannot get QML context";
        return 0;
    }
    qmlcontext->setContextProperty("chessController", &chessController);
    engine.load(QUrl(QStringLiteral("qml/main.qml")));

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

示例15: main

//![0]
int main(int argc, char ** argv)
{
    QGuiApplication app(argc, argv);

    QList<QObject*> dataList;
    dataList.append(new DataObject("Item 1", "red"));
    dataList.append(new DataObject("Item 2", "green"));
    dataList.append(new DataObject("Item 3", "blue"));
    dataList.append(new DataObject("Item 4", "yellow"));

    QQuickView view;

    view.setResizeMode(QQuickView::SizeRootObjectToView);
    QQmlContext *ctxt = view.rootContext();
     ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));

#ifdef linux
     CPUTimer timer(CLOCK_PROCESS_CPUTIME_ID);
#endif
//![0]

#if 1
    // add precompiled files
    QQmlEngine *engine = view.engine();
    QQmlEnginePrivate::get(engine)->v4engine()->iselFactory.reset(new QV4::JIT::ISelFactory);
    QmcLoader loader(engine);

#ifdef linux
    timer.start();
#endif
    QQmlComponent *component = loader.loadComponent(":/view.qmc");

    if (!component) {
        qDebug() << "Could not load component";
        return -1;
    }
    if (!component->isReady()) {
        qDebug() << "Component is not ready";
        if (component->isError()) {
            foreach (const QQmlError &error, component->errors()) {
                qDebug() << error.toString();
            }
        }
开发者ID:liqiu,项目名称:qmlc,代码行数:44,代码来源:main.cpp


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