本文整理汇总了C++中QDeclarativeContext::setContextProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ QDeclarativeContext::setContextProperty方法的具体用法?C++ QDeclarativeContext::setContextProperty怎么用?C++ QDeclarativeContext::setContextProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDeclarativeContext
的用法示例。
在下文中一共展示了QDeclarativeContext::setContextProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQuickView viewer;
PackageManager *pm = new PackageManager(&viewer);
QDeclarativeContext *context = viewer.rootContext();
context->setContextProperty("initialstate", "mainview");
context->setContextProperty("mainWindow", &viewer);
viewer.engine()->addImageProvider(QLatin1String("icons"), new IconProvider);
viewer.engine()->addImportPath("/usr/lib/qt5/imports");
qmlRegisterType<Package>("Package", 1,0, "Package");
qmlRegisterType<PackageGroup>("Package", 1,0, "PackageGroup");
qmlRegisterType<PackageMarkings>("Package", 1, 0, "PackageMarkings");
qmlRegisterType<Repository>("Repository", 1,0, "Repository");
viewer.setMainQmlFile(QLatin1String("qml/package-manager/main.qml"));
viewer.setOrientation(QQuickView::ScreenOrientationAuto);
viewer.showExpanded();
return app.exec();
}
示例2: QObject
SFAbstractApplicationUI::SFAbstractApplicationUI(bb::cascades::Application *app) : QObject(app) {
//register meta types for SF classes and enums
sfRegisterMetaTypes();
//Setup SFDC connection info
SFAccountManager::setClientId(SFRemoteAccessConsumerKey);
SFAccountManager::setRedirectUri(SFOAuthRedirectURI);
//In addition, you can set up scope for your token like below.
/*
QList<QString> scopes;
scopes.append("api");
SFAccountManager::setScopes(scopes);
*/
//setup API objects
SFRestAPI::instance()->setApiVersion(SFDefaultRestApiVersion);
//Expose API objects to QML
QDeclarativeEngine *engine = QmlDocument::defaultDeclarativeEngine();
QDeclarativeContext *context = engine ? engine->rootContext() : NULL;
if (context) {
context->setContextProperty("SFAccountManager", SFAccountManager::instance());
context->setContextProperty("SFAuthenticationManager", SFAuthenticationManager::instance());
context->setContextProperty("SFRestAPI", SFRestAPI::instance());
} else {
sfWarning() << "[SFAbstractApplicationUI] Failed to grab shared QML declarative engine. SF APIs may not be accessible in QML.";
}
//connect some slots
connect(app, SIGNAL(aboutToQuit()), SFAuthenticationManager::instance(), SLOT(onAboutToQuit()));
connect(app, SIGNAL(fullscreen()), SFAuthenticationManager::instance(), SLOT(onAppStart()));
}
示例3: of
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 );
}
}
示例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"));
}
示例5: 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();
}
示例6: 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);
}
示例7: 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();
}
示例8: mapLoader
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_mapModel(&m_fieldModel, this)
{
ui->setupUi(this);
MapLoader mapLoader(&m_mapModel, &m_fieldModel);
mapLoader.loadMap("/home/guillaume/Workspace/Test_QGraphicsMap/1.map");
this->ui->graphicsView->setSource(QUrl("qrc:/qml/qml/main.qml"));
QDeclarativeContext *ctxt = this->ui->graphicsView->rootContext();
ctxt->setContextProperty("MapModel", &m_mapModel);
ctxt->setContextProperty("FieldModel", &m_fieldModel);
//MapModel::getInstance()->debug();
}
示例9: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Register QML bindings fo DrumEngine and TouchEvents
#ifdef Q_OS_SYMBIAN
qmlRegisterType<DrumEngine>("DrumEngine", 1,0, "DrumEngine");
#endif
qmlRegisterType<TouchEvents>("TouchEvents", 1,0, "TouchEvents");
QmlViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
// Check for VGA resolution and inform QML. Needed for some
// gfx layouting on on Symbian devices with VGA resolution (E6).
QDesktopWidget *desktop = QApplication::desktop();
const QRect screenRect = desktop->screenGeometry();
QDeclarativeContext* context = viewer.rootContext();
if (screenRect.width() == 640 && screenRect.height() == 480) {
context->setContextProperty("screenVGA", true);
} else {
context->setContextProperty("screenVGA", false);
}
// Provide information whether running in simulator. Used in Pad.qml.
#ifdef QT_SIMULATOR
context->setContextProperty("simulator", true);
#else
context->setContextProperty("simulator", false);
#endif
// Select the main.qml according to platform.
#ifdef Q_OS_SYMBIAN
viewer.setMainQmlFile(QLatin1String("qml/symbian/main.qml"));
#else
viewer.setMainQmlFile(QLatin1String("qml/harmattan/main.qml"));
#endif
// Enable OpenGL rendering
QGLFormat fmt = QGLFormat::defaultFormat();
fmt.setDirectRendering(true);
fmt.setDoubleBuffer(true);
QGLWidget *glWidget = new QGLWidget(fmt);
viewer.setViewport(glWidget);
viewer.showFullScreen();
return app.exec();
}
示例10: main
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QDeclarativeView v;
v.setAttribute(Qt::WA_OpaquePaintEvent);
v.setAttribute(Qt::WA_NoSystemBackground);
v.viewport()->setAttribute(Qt::WA_OpaquePaintEvent); v.viewport()->setAttribute(Qt::WA_NoSystemBackground);
QDeclarativeContext *c = v.rootContext();
c->setContextProperty("fileBrowserUtils", new Utils);
if (QFile::exists("main.qml"))
v.setSource(QUrl::fromLocalFile("main.qml"));
else
v.setSource(QUrl("qrc:/qml/main.qml"));
if (QCoreApplication::arguments().contains("-fullscreen")) {
qDebug() << Q_FUNC_INFO << "Starting in fullscreen mode";
v.showFullScreen();
} else {
qDebug() << Q_FUNC_INFO << "Starting in windowed mode";
v.show();
}
return a.exec();
}
示例11: QDeclarativeView
InitQML::InitQML(QWidget *MainW,QWidget *parent) :
QDeclarativeView(parent),mainW(MainW)
{
resetDone = false;
QPalette pal = palette();
pal.setColor(QPalette::Window,QColor("black"));
// setAutoFillBackground(true);
pal.setColor( QPalette::Background, Qt::transparent);
setPalette(pal);
rip = new ResourceImageProvider(QDeclarativeImageProvider::Pixmap);
rip->mainW = mainW;
engine()->addImageProvider("background",rip);
setSource(QUrl("qrc:/qml/init.qml"));
QDeclarativeContext *context = rootContext();
context->setContextProperty("backgroundColor",
QPalette().color(QPalette::Window));
QGraphicsObject *object = this->rootObject();
QObject *rect = object->findChild<QObject*>("imageRect");
/*
if (!rect)
qDebug() <<"Image Rect not found !!!!!!" << __FILE__ << __LINE__;
else {
rect->setProperty("src",);
*/
}
示例12: changed
void tst_QDeclarativePropertyMap::changed()
{
QDeclarativePropertyMap map;
QSignalSpy spy(&map, SIGNAL(valueChanged(const QString&, const QVariant&)));
map.insert(QLatin1String("key1"),100);
map.insert(QLatin1String("key2"),200);
QCOMPARE(spy.count(), 0);
map.clear(QLatin1String("key1"));
QCOMPARE(spy.count(), 0);
//make changes in QML
QDeclarativeEngine engine;
QDeclarativeContext *ctxt = engine.rootContext();
ctxt->setContextProperty(QLatin1String("testdata"), &map);
QDeclarativeComponent component(&engine);
component.setData("import QtQuick 1.0\nText { text: { testdata.key1 = 'Hello World'; 'X' } }",
QUrl::fromLocalFile(""));
QVERIFY(component.isReady());
QDeclarativeText *txt = qobject_cast<QDeclarativeText*>(component.create());
QVERIFY(txt);
QCOMPARE(txt->text(), QString('X'));
QCOMPARE(spy.count(), 1);
QList<QVariant> arguments = spy.takeFirst();
QCOMPARE(arguments.count(), 2);
QCOMPARE(arguments.at(0).toString(),QLatin1String("key1"));
QCOMPARE(arguments.at(1).value<QVariant>(),QVariant("Hello World"));
QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World"));
}
示例13: main
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QWidget wi(0);
PDPI = wi.logicalDpiX(); // physical resolution
DPI = PDPI; // logical drawing resolution
DPMM = DPI / INCH; // dots/mm
runtime = new Runtime;
MScore::init();
seq = new Seq;
if (!seq->init()) {
printf("cannot initialize sequencer\n");
exit(-1);
}
qmlRegisterType<ScoreView>("MuseScore", 1, 0, "ScoreView");
QDeclarativeView view;
view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
QDeclarativeContext* ctxt = view.rootContext();
ctxt->setContextProperty(QLatin1String("runtime"), runtime);
// registering only for exposing the Runtime::Orientation enum
qmlRegisterUncreatableType<Runtime>("Qt", 4, 7, "Orientation", QString());
qmlRegisterUncreatableType<Runtime>("QtQuick", 1, 0, "Orientation", QString());
view.setSource(QUrl("qrc:/mplayer.qml"));
view.show();
return app.exec();
}
示例14: main
int main(int argc, char **argv)
{
qRegisterMetaType<QVector<QFileInfo> >();
qmlRegisterType<DirModel>("FBrowser", 1, 0, "DirModel");
QApplication a(argc, argv);
QDeclarativeView v;
QDeclarativeEngine *e = v.engine();
e->addImageProvider(QLatin1String("nemoThumbnail"), new FileThumbnailImageProvider);
QDeclarativeContext *c = v.rootContext();
c->setContextProperty("fileBrowserUtils", new Utils);
if (QFile::exists("main.qml"))
v.setSource(QUrl::fromLocalFile("main.qml"));
else
v.setSource(QUrl("qrc:/qml/main.qml"));
if (QCoreApplication::arguments().contains("-fullscreen")) {
qDebug() << Q_FUNC_INFO << "Starting in fullscreen mode";
v.showFullScreen();
} else {
qDebug() << Q_FUNC_INFO << "Starting in windowed mode";
v.show();
}
return a.exec();
}
示例15: main
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
qmlRegisterType<FeedHelper>("FeedHelper", 1, 0, "FeedHelper");
viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer->setMainQmlFile(QLatin1String("qml/newsg/main.qml"));
QDeclarativeContext *ctxt = viewer->rootContext();
ShareHelper sh;
ctxt->setContextProperty("Share", &sh);
viewer->setAttribute(Qt::WA_OpaquePaintEvent);
viewer->setAttribute(Qt::WA_NoSystemBackground);
viewer->viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
viewer->viewport()->setAttribute(Qt::WA_NoSystemBackground);
viewer->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
viewer->showExpanded();
return app->exec();
}