本文整理汇总了C++中QQmlApplicationEngine::rootContext方法的典型用法代码示例。如果您正苦于以下问题:C++ QQmlApplicationEngine::rootContext方法的具体用法?C++ QQmlApplicationEngine::rootContext怎么用?C++ QQmlApplicationEngine::rootContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QQmlApplicationEngine
的用法示例。
在下文中一共展示了QQmlApplicationEngine::rootContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
Playlist playlist(QString("simon"));
playlist.addSong(new Song("Ziggy Stardust", "David Bowie", "Ziggy Stardust and the ...", "/home/simon/Music/ziggy.mp3", 142));
playlist.addSong(new Song("Five Years", "David Bowie", "Ziggy Stardust and the ...", "/home/simon/Music/five.mp3", 142));
QList<QObject *> playlistlist;
playlistlist.append(&playlist);
Player player(&playlist);
player.setCurrentPlaylist(&playlist);
engine.rootContext()->setContextProperty("player", &player);
engine.rootContext()->setContextProperty("playlistlist", QVariant::fromValue(playlistlist));
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
示例2: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
SettingsValult * settings = &Singleton<SettingsValult>::Instance();
SettingsController settingsController;
FileController fileController;
SoundController soundController;
SpeechController speechController;
LocaleObject * uiLocale = settings->getUiLocale();
if (uiLocale != NULL)
{
QLocale::setDefault(*uiLocale->locale());
}
QTranslator translator;
translator.load(QLocale(), "speech-apps", "_", ":/qml/qml/i18n/", ".qm");
app.installTranslator(&translator);
QQmlApplicationEngine engine;
engine.addImportPath(QApplication::applicationDirPath());
engine.load(QUrl(QStringLiteral("qrc:/qml/qml/main.qml")));
engine.rootContext()->setContextProperty("settingsController", &settingsController);
engine.rootContext()->setContextProperty("fileController", &fileController);
engine.rootContext()->setContextProperty("soundController", &soundController);
engine.rootContext()->setContextProperty("speechController", &speechController);
return app.exec();
}
示例3: main
int main(int argc, char *argv[])
{
using namespace std;
#ifdef TEST
// run all test cases first
cout << "execute tests" << endl;
TestMain tests;
tests.execute();
#endif
QGuiApplication app(argc, argv);
UiEventDispatcher dispatcher;
uGridLayout layout(1200, 1600);
uDebugPrinter debugger;
qmlRegisterType<FileSaveDialog>("MyModules", 1, 0, "FileSaveDialog");
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("gridLayout", &layout);
engine.rootContext()->setContextProperty("dispatcher", &dispatcher);
engine.rootContext()->setContextProperty("uDebugger", &debugger);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
示例4: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStandardItemModel model;
model.appendRow(new QStandardItem("Norway"));
model.appendRow(new QStandardItem("Netherlands"));
model.appendRow(new QStandardItem("New Zealand"));
model.appendRow(new QStandardItem("Namibia"));
model.appendRow(new QStandardItem("Nicaragua"));
model.appendRow(new QStandardItem("North Korea"));
model.appendRow(new QStandardItem("Northern Cyprus "));
model.appendRow(new QStandardItem("Sweden"));
model.appendRow(new QStandardItem("Denmark"));
QStringList strings;
strings << "Norway" << "Sweden" << "Denmark";
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("standardmodel", &model);
engine.rootContext()->setContextProperty("stringmodel", strings);
engine.load(QUrl("main.qml"));
QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
if ( !window ) {
qWarning("Error: Your root item has to be a Window.");
return -1;
}
window->show();
return app.exec();
}
示例5: main
int main(int argc, char *argv[])
{
QList<Player> Players;
QGuiApplication app(argc, argv);
Player player1;
Player player2;
Player player3;
Player player4;
Player player5;
Player player6;
Player player7;
Player player8;
QQmlApplicationEngine engine;
QCoreApplication::setApplicationName("DoorCounter");
QCoreApplication::setOrganizationName("HazardousLiquids");
QCoreApplication::setOrganizationDomain(".com");
engine.rootContext()->setContextProperty("player1", &player1);
engine.rootContext()->setContextProperty("player2", &player2);
engine.rootContext()->setContextProperty("player3", &player3);
engine.rootContext()->setContextProperty("player4", &player4);
engine.rootContext()->setContextProperty("player5", &player5);
engine.rootContext()->setContextProperty("player6", &player6);
engine.rootContext()->setContextProperty("player7", &player7);
engine.rootContext()->setContextProperty("player8", &player8);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
示例6: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
#define PACKAGE_VERSION "qmlnect", 1, 0,
qmlRegisterType<QNiTE>("qmlnect", 1, 0, "QNiTE");
qmlRegisterType<QNiTETrackerRenderer>("qmlnect", 1, 0, "QNiTETrackerRenderer");
qmlRegisterType<QNiTEColorRenderer>("qmlnect", 1, 0, "QNiTEColorRenderer");
qmlRegisterUncreatableType<QNiTEUser>("qmlnect", 1, 0, "QNiTEUser", "This class cannot be created directly. You can get references to tracked users from the QNiTE class.");
qmlRegisterType<DWSoundSystem>("qmlnect", 1, 0, "SoundSystem");
qmlRegisterUncreatableType<nSoundSystem>( PACKAGE_VERSION "NSoundSystem", QStringLiteral("") );
qmlRegisterUncreatableType<nSoundBag>( PACKAGE_VERSION "NSoundBag", QStringLiteral("") );
qmlRegisterUncreatableType<nSoundBuffer>( PACKAGE_VERSION "NSoundBuffer", QStringLiteral("") );
qmlRegisterUncreatableType<nSoundListener>( PACKAGE_VERSION "NSoundListener", QStringLiteral("") );
qmlRegisterUncreatableType<nSoundSource>( PACKAGE_VERSION "NSoundSource", QStringLiteral("") );
qmlRegisterUncreatableType<nSoundStream>( PACKAGE_VERSION "NSoundStream", QStringLiteral("") );
qmlRegisterUncreatableType<nSoundStreamer>( PACKAGE_VERSION "NSoundStreamer", QStringLiteral("") );
qmlRegisterUncreatableType<nSoundStreamerPlaylist>( PACKAGE_VERSION "NSoundStreamerPlaylist", QStringLiteral("") );
qmlRegisterType<ImageData>("qmlnect", 1, 0, "ImageData");
qmlProtectModule("qmlnect", 1);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("cwd", QDir::currentPath());
engine.rootContext()->setContextProperty("qmlEngine", &engine);
engine.load(QUrl(QStringLiteral("qrc:/qml/ControlWindow.qml")));
return app.exec();
}
示例7: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("ScreenW",1920);//1920x1080
engine.rootContext()->setContextProperty("ScreenH",1080);
DiceResultModel* model = new DiceResultModel();
engine.rootContext()->setContextProperty("_diceModel",model);
/* QTextDocument text(NULL);
CppHighLighter cppHighLighter(&text);
engine.rootContext()->setContextProperty("_hightedDoc",&text);*/
//engine.rootContext()->setContextProperty("CppHighLightedDocument",720);
QmlControler ctr;
ctr.setResultModel(model);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QList<QObject*> roots = engine.rootObjects();
QObject* root = roots.at(0);
QObject::connect(root,SIGNAL(rollDiceCmd(QString)),&ctr,SLOT(rollDice(QString)));
ctr.setEngine(&engine);
ctr.setVisible(true);
return app.exec();
}
示例8: main
int main(int argc, char *argv[])
{
//#if defined(WIN32) && defined(_DEBUG) //TODO: restore this to eliminate console in windows release builds
#if defined(WIN32)
AllocConsole();
//TODO: add an icon to distribution then enable the commented out code below
//QPixmap px(":/images/lightwallet.png");
//HICON hIcon = qt_pixmapToWinHICON(px);
//SetConsoleIcon(hIcon);
freopen("CONOUT$", "wb", stdout);
freopen("CONOUT$", "wb", stderr);
printf("testing stdout\n");
fprintf(stderr, "testing stderr\n");
#endif
QGuiApplication app(argc, argv);
app.setApplicationName(QStringLiteral("BitShares %1 Light Wallet").arg(BTS_BLOCKCHAIN_SYMBOL));
app.setOrganizationName(BTS_BLOCKCHAIN_NAME);
app.setOrganizationDomain("bitshares.org");
app.setApplicationVersion("1.0 RC 1");
//Fire up the NTP system
bts::blockchain::now();
#ifdef BTS_TEST_NETWORK
QQmlDebuggingEnabler enabler;
#endif
qmlRegisterType<LightWallet>("org.BitShares.Types", 1, 0, "LightWallet");
qmlRegisterUncreatableType<Account>("org.BitShares.Types", 1, 0, "Account",
QStringLiteral("Accounts can only be created in backend."));
qmlRegisterUncreatableType<Balance>("org.BitShares.Types", 1, 0, "Balance",
QStringLiteral("Balances can only be created in backend."));
qmlRegisterUncreatableType<TransactionSummary>("org.BitShares.Types", 1, 0, "TransactionSummary",
QStringLiteral("Transaction summaries can only be created in backend."));
qmlRegisterUncreatableType<LedgerEntry>("org.BitShares.Types", 1, 0, "LedgerEntry",
QStringLiteral("Ledger entries can only be created in backend."));
QQmlApplicationEngine engine;
auto nam = engine.networkAccessManager();
if( nam )
{
QNetworkDiskCache* cache = new QNetworkDiskCache(&engine);
cache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/cache");
nam->setCache(cache);
}
#if QT_VERSION >= 0x050400
engine.rootContext()->setContextProperty("PlatformName", QSysInfo::prettyProductName());
#endif
engine.rootContext()->setContextProperty("ManifestUrl", QStringLiteral("https://bitshares.org/manifest.json"));
engine.rootContext()->setContextProperty("AppName", QStringLiteral("lw_%1").arg(BTS_BLOCKCHAIN_SYMBOL).toLower());
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
return app.exec();
}
示例9: main
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QObject* global = new QObject();
engine.rootContext()->setContextObject(global);
engine.rootContext()->setContextProperty("global", global);
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
return app.exec();
}
示例10: main
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
CLog::SetLevel(CLog::Error);
QApplication app(argc, argv);
QQmlApplicationEngine engine;
Parameters parameters(QGuiApplication::applicationDirPath());
KeyEmitter keyEmitter;
CameraWorker camera;
/**
* Share context for omxplayer
*/
qmlRegisterType<VideoItem>("com.phototwix.components", 1, 0, "VideoItem");
qmlRegisterType<Template>("com.phototwix.components", 1, 0, "Template");
qmlRegisterType<TemplatePhotoPosition>("com.phototwix.components", 1, 0, "TemplatePhotoPosition");
qmlRegisterType<PhotoGallery>("com.phototwix.components", 1, 0, "PhotoGallery");
qmlRegisterType<Photo>("com.phototwix.components", 1, 0, "Photo");
qmlRegisterType<PhotoPart>("com.phototwix.components", 1, 0, "PhotoPart");
qmlRegisterType<Mail>("com.phototwix.components", 1, 0, "Mail");
qmlRegisterType<KeyEmitter>("com.phototwix.components", 1, 0, "KeyEmitter");
qmlRegisterType<PhotoQueueManager>("com.phototwix.components", 1, 0, "PhotoQueueManager");
qmlRegisterType<WifiManager>("com.phototwix.components", 1, 0, "WifiManager");
qmlRegisterType<WifiItem>("com.phototwix.components", 1, 0, "WifiItem");
qmlRegisterType<RaspiGPIO>("com.phototwix.components", 1, 0, "RaspiGPIO");
qmlRegisterType<PrinterManager>("com.phototwix.components", 1, 0, "PrinterManager");
qmlRegisterType<CameraWorker>("com.phototwix.components", 1, 0, "CameraWorker");
engine.rootContext()->setContextProperty("applicationDirPath", QGuiApplication::applicationDirPath());
engine.rootContext()->setContextProperty("parameters", ¶meters);
engine.rootContext()->setContextProperty("photoGallery", parameters.getPhotogallery());
engine.rootContext()->setContextProperty("keyEmitter", &keyEmitter);
CLog::Write(CLog::Debug, ("Application dir path " + QGuiApplication::applicationDirPath()).toStdString());
if (parameters.getIsMirror()) {
engine.rootContext()->setContextProperty("camera", &camera);
engine.load(QUrl(QStringLiteral("qrc:/MirrorScreenMain.qml")));
} else {
engine.load(QUrl(QStringLiteral("qrc:/CommandScreenMain.qml")));
}
parameters.hideCursor();
return app.exec();
}
示例11: main
int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);
QGuiApplication app(argc, argv);
QSize baseSize(1280,1024);
QSize screenSize(app.primaryScreen()->size());
if(!FKUtility::loadImageset("images",screenSize)){
qDebug("unable load images");
}
if(!FKUtility::loadImageset("skillIcons",screenSize)){
qDebug("unable load skillIcons");
}
FKUtility::ResourceLocator resources;
if(resources.load("music")!=FKUtility::ResourceLocator::loadingSuccess){
qDebug("unable load music resource");
}
if(!resources.load("models")!=FKUtility::ResourceLocator::loadingSuccess){
qDebug("unable load models resource");
}
if(!resources.load("sprites")!=FKUtility::ResourceLocator::loadingSuccess){
qDebug("unable load sprites resource");
}
qreal sizeSet=std::max(((qreal)screenSize.height())/((qreal)baseSize.height()),
((qreal)screenSize.width ())/((qreal)baseSize.width ()));
QQmlApplicationEngine engine;
ADD_QML_TYPE(BalancedComponent);
ADD_QML_TYPE(PlayerBase);
ADD_QML_TYPE(HeroObject);
ADD_QML_TYPE(PathMap);
ADD_QML_TYPE(PathFinder);
ADD_QML_ABSTRACT_TYPE(PathFinderAlgorithm);
ADD_QML_TYPE(PathFinderAStarAlgorithm);
engine.rootContext()->setContextProperty("sizeSet",sizeSet);
engine.rootContext()->setContextProperty("baseHeight",baseSize.height());
engine.rootContext()->setContextProperty("baseWidth",baseSize.width());
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
QMetaObject::invokeMethod(engine.rootObjects().at(0),"show");
return app.exec();
}
示例12: main
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
Jose_Clock clock;
QQmlApplicationEngine engine;
LoginManager user_login;
engine.rootContext()->setContextProperty("Clock",&clock);
engine.rootContext()->setContextProperty("Login",&user_login);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
示例13: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ChessBoard board;
board.Initialise();
QQmlApplicationEngine engine;
QUrl appPath(QString("%1").arg(app.applicationDirPath()));
engine.rootContext()->setContextProperty("appPath", appPath);
engine.rootContext()->setContextProperty("chessModel", &board);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
示例14: main
int main(int argc, char **argv)
{
Application app(argc, argv);
// Load configuration
Config * config = new Config();
config->load();
// Set domain
app.setOrganizationName("liri-project");
app.setOrganizationDomain("liri-project.me");
app.setApplicationName("liri-browser");
// Load Translations
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(),
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);
QTranslator translator;
translator.load(":/translations/" + QLocale::system().name());
app.installTranslator(&translator);
qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "0.0.0.0:9992");
// Initialize QtWebEngine (and some attempts to activate pepper plugins, but it doesn't work)
//QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
QtWebEngine::initialize();
//QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
/*QWebEngineSettings *defaultSettings = QWebEngineSettings::globalSettings();
defaultSettings->setAttribute(QWebEngineSettings::PluginsEnabled, true);
QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);*/
QQmlApplicationEngine * appEngine = new QQmlApplicationEngine();
//appEngine.rootContext()->setContextProperty("utils", &utils);
qmlRegisterType<ClipBoardAdapter>("Clipboard", 1, 0, "Clipboard");
appEngine->load(QUrl("qrc:/qml/DesktopApplication.qml"));
QMetaObject::invokeMethod(appEngine->rootObjects().first(), "load");
appEngine->rootContext()->setContextProperty("G_Cursor",new Cursor);
// Load plugins
PluginsEngine * pluginsEngine = new PluginsEngine(appEngine, config);
appEngine->rootContext()->setContextProperty("PluginsEngine", pluginsEngine);
pluginsEngine->loadPlugins();
pluginsEngine->trigger(QString("load"));
return app.exec();
}
示例15: main
int main(int argc, char *argv[]) {
QGuiApplication app(argc, argv);
// QQmlEngine engine;
scene::GameSceneController controller;
sprouts::GameLogicController gameController;
// engine.rootContext()->setContextProperty("game", &controller);
QObject::connect(&controller, SIGNAL(gameStarts(int, int, QVector<QPoint>)),
&gameController, SLOT(init(int, int, QVector<QPoint>)));
QObject::connect(&controller, SIGNAL(newLineAdded(int,int,QVector<QPoint>,QPoint)),
&gameController, SLOT(doTurn(int,int,QVector<QPoint>,QPoint)));
QObject::connect(&gameController, SIGNAL(turnEnds(bool)),
&controller, SLOT(turnEnds(bool)));
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("game", &controller);
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
return app.exec();
}