本文整理汇总了C++中QQmlContext类的典型用法代码示例。如果您正苦于以下问题:C++ QQmlContext类的具体用法?C++ QQmlContext怎么用?C++ QQmlContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QQmlContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: main
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QString path(".");
if (argc == 2) {
path = argv[1];
}
QtQuick2ApplicationViewer viewer;
GitProject git;
git.setCurrentPath(path);
QQmlContext *context = viewer.rootContext();
context->setContextProperty("gGit", &git);
viewer.setMainQmlFile(QStringLiteral("qml/GitGrown/main.qml"));
viewer.showExpanded();
return app.exec();
}
示例3: vlc_open
bool Chimera_Win::onWindowAttached( FB::AttachedEvent *evt, FB::PluginWindowWin* w )
{
vlc_open();
m_quickViewPtr.reset( new QQuickView );
m_quickViewPtr->setResizeMode( QQuickView::SizeRootObjectToView );
m_quickViewPtr->setProperty( "_q_embedded_native_parent_handle", WId( w->getHWND() ) );
m_quickViewPtr->setFlags( m_quickViewPtr->flags() | Qt::FramelessWindowHint );
QQmlContext* context = m_quickViewPtr->rootContext();
m_qmlVlcPlayer = new QmlVlcSurfacePlayerProxy( (vlc::player*)this, m_quickViewPtr.data() );
m_qmlVlcPlayer->classBegin();
context->setContextProperty( "vlcPlayer", QVariant::fromValue( m_qmlVlcPlayer ) );
process_startup_options();
m_quickViewPtr->setSource( getQmlSource() );
MoveWindow( (HWND)m_quickViewPtr->winId(), 0, 0, w->getWindowWidth(), w->getWindowHeight(), FALSE );
m_quickViewPtr->show();
return false;
}
示例4: 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();
}
示例5: 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();
}
示例6: updateStatistics
void MainWindow::updateStatistics()
{
QQmlContext* context = m_statistics_view->rootContext();
context->setContextProperty("network_total_count", m_network_statistics->totalCount());
context->setContextProperty("network_successful_count", m_network_statistics->successfulCount());
context->setContextProperty("network_failed_count", m_network_statistics->failedCount());
context->setContextProperty("network_slow_count", m_network_statistics->tooSlowConnectionsCount());
context->setContextProperty("network_pending_count", m_network_statistics->pendingConnectionsCount());
}
示例7: main
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
qDebug() << "library paths" << app.libraryPaths();
QQmlApplicationEngine engine;
engine.addImportPath("libview");
// We must set the locale always to C as some tools won't work correctly without it.
// e.g. decimal points will always be "." this way.
QLocale::setDefault(QLocale::c());
qDebug() << "QLibrary" << QLibraryInfo::location(QLibraryInfo::LibraryExecutablesPath);
qDebug() << "QLibraryPrefix" << QLibraryInfo::location(QLibraryInfo::PrefixPath);
qDebug() << "QLibraryLocation" << QLibraryInfo::location(QLibraryInfo::LibrariesPath);
QtWebEngine::initialize();
PythonLoader pythonLoader{&app};
QObject* dice = pythonLoader.getObject("dice.main", "Dice");
if (!dice) {
qDebug() << "Could not initialize the python core!";
return -1;
}
QQmlContext* context = engine.rootContext();
QVariant vEngine, vContext;
vEngine.setValue(&engine);
vContext.setValue(context);
dice->setProperty("qmlEngine", vEngine);
dice->setProperty("qmlContext", vContext);
context->setContextProperty("dice", dice);
engine.load(QUrl("libview/Window/main.qml"));
app.topLevelWindows().first()->setIcon(QIcon("libview/Window/images/dice_logo_grey.svg"));
return app.exec();
}
示例8: dockQmlToWidget
QWidget* GUIExchangesWidget::dockQmlToWidget()
{
QQuickView* pExchangesWindow = new QQuickView;
QWidget* pPlaceHolder = 0;
if ( pExchangesWindow )
{
QQmlContext* pContext = pExchangesWindow->rootContext();
if ( pContext )
{
pContext->setContextProperty( "GUI20Skin", &GUI20Skin::Instance() );
}
QQmlEngine* pEngine = pExchangesWindow->engine();
if ( pEngine )
{
m_pQmlImageProvider = new QmlImageProvider();
pEngine->addImageProvider( "exchangesImages", m_pQmlImageProvider );
}
pExchangesWindow->setSource( QUrl( QStringLiteral( "qrc:/qml/qtquick_controls/qml/QmlGUIExchangesWindow.qml" ) ) );
QQuickItem* pRootObject = pExchangesWindow->rootObject();
if ( pRootObject )
{
m_pExchangesControl = pRootObject->findChild<GUIExchangesControl*>();
if ( m_pExchangesControl )
{
}
}
pPlaceHolder = QWidget::createWindowContainer( pExchangesWindow, this );
if ( pPlaceHolder )
{
pPlaceHolder->setMinimumSize( 500, 170 );
pPlaceHolder->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
}
}
return pPlaceHolder;
}
示例9: 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();
}
示例10: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setDatabaseName("terkas");
db.setHostName("localhost");
db.setUserName("postgres");
db.setPassword("monrepo");
db.setPort(5432);
if (!db.open()) {
qDebug() << "ERROR: Database not opened: " << db.lastError().text();
return 0;
}
StatisticsModel *statisticsModel = new StatisticsModel;
QQmlApplicationEngine engine;
QQmlContext *ctx = engine.rootContext();
ctx->setContextProperty("statisticsModel", QVariant::fromValue(statisticsModel));
engine.load(QUrl(QStringLiteral("qrc:/qml/Main.qml")));
return app.exec();
}
示例11: main
int main(int argc, char *argv[])
{
//! [0]
QGuiApplication app(argc, argv);
QtWebView::initialize();
//! [0]
QGuiApplication::setApplicationDisplayName(QCoreApplication::translate("main",
"QtWebView Example"));
QCommandLineParser parser;
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
parser.setApplicationDescription(QGuiApplication::applicationDisplayName());
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("url", "The initial URL to open.");
QStringList arguments = app.arguments();
#ifdef Q_OS_WINRT
arguments.removeAt(1); // The launcher always passes in the -ServerName parameter, breaking the command line parser
#endif
parser.process(arguments);
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")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
示例12: initializeEngine
void ManaPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
Mana::ResourceManager *resourceManager = new Mana::ResourceManager(engine);
Mana::AttributeDB *attributeDB = new Mana::AttributeDB(engine);
Mana::HairDB *hairDB = new Mana::HairDB(engine);
Mana::ItemDB *itemDB = new Mana::ItemDB(engine);
Mana::MonsterDB *monsterDB = new Mana::MonsterDB(engine);
Mana::NpcDB *npcDB = new Mana::NpcDB(engine);
Mana::RaceDB *raceDB = new Mana::RaceDB(engine);
QQmlContext *context = engine->rootContext();
context->setContextProperty("resourceManager", resourceManager);
context->setContextProperty("attributeDB", attributeDB);
context->setContextProperty("hairDB", hairDB);
context->setContextProperty("itemDB", itemDB);
context->setContextProperty("monsterDB", monsterDB);
context->setContextProperty("npcDB", npcDB);
context->setContextProperty("raceDB", raceDB);
int errorCode = enet_initialize();
Q_ASSERT(errorCode == 0);
atexit(enet_deinitialize);
}
示例13: rootContext
void BrowserWindowMobile::setupDeclarativeEnvironment()
{
QQmlContext* context = rootContext();
context->setContextProperty("BrowserWindow", this);
DatabaseManager* dbManager = DatabaseManager::instance();
context->setContextProperty("HistoryModel", dbManager->historyDataBaseModel());
context->setContextProperty("BookmarkModel", dbManager->bookmarkDataBaseModel());
context->setContextProperty("TabsModel", new TabsModel(this));
context->setContextProperty("UrlTools", new UrlTools(this));
QObject::connect(engine(), SIGNAL(quit()), qApp, SLOT(quit()));
setResizeMode(QQuickView::SizeRootObjectToView);
#if defined(SNOWSHOE_MEEGO_HARMATTAN)
reportContentOrientationChange(Qt::PortraitOrientation);
setSource(QUrl("qrc:///mobile/qml/main-harmattan.qml"));
#else
setSource(QUrl("qrc:///mobile/qml/Main.qml"));
#endif
}
示例14: 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();
}
示例15: main
int main(int argc, char *argv[])
{
Py_SetProgramName(GetWC(argv[0]));
qDebug()<<"Version Of QT: "<<qVersion();
// Load env from QML path
char* qml_env_path;
qml_env_path = getenv("AFERMER_QML_PATH");
fs::path qml_app_path("/");
if (qml_env_path == NULL)
{
std::cerr << "AFERMER_QML_PATH not present or directory does not exist. Take directory from startup " << std::endl;
fs::path full_path( fs::initial_path<fs::path>() );
full_path = fs::system_complete( fs::path( argv[0] ) );
qml_app_path = full_path.parent_path() / "qml";
if (!fs::exists( qml_app_path ))
{
std::cerr << "QML directory ("
<< qml_app_path
<< ") not found. Exit" << std::endl;
return 1;
}
}
else
{
qml_app_path = fs::path(qml_env_path);
}
fs::path qml_app_icon_path(qml_app_path);
qml_app_icon_path /= "icons";
qml_app_icon_path /= "soft_circl_icon.png";
qml_app_path /= "main.qml";
QGuiApplication app(argc, argv);
app.setOrganizationName("afermer");
app.setWindowIcon(QIcon(qml_app_icon_path.string().c_str()));
BladeState::declareQML();
JobState::declareQML();
TaskState::declareQML();
QQmlApplicationEngine engine;
General general;
JobsModel jobs_model;
BladesModel blades_model;
UsersModel users_model;
TasksModel tasks_model;
QQmlContext *ctxt =engine.rootContext();
//ctxt->setContextProperty("server_exist", "yes");
ctxt->setContextProperty("General", &general);
ctxt->setContextProperty("JobsModel", &jobs_model);
ctxt->setContextProperty("BladesModel", &blades_model);
ctxt->setContextProperty("UsersModel", &users_model);
ctxt->setContextProperty("TasksModel", &tasks_model);
engine.load(QUrl::fromLocalFile(qml_app_path.string().c_str()));
QObject *rootObject = engine.rootObjects().first();
rootObject->setProperty("visible", true);
engine.collectGarbage();
return app.exec();
}