int main(int argc, char *argv[]) { qmlRegisterType<Recorder>("harbour.recorder", 1, 0, "Recorder"); qmlRegisterType<DirectoryModel>("harbour.recorder", 1, 0, "DirectoryModel"); auto app = SailfishApp::application(argc, argv); QCoreApplication::setOrganizationName("harbour-recorder"); QCoreApplication::setOrganizationDomain("www.corne.info"); QCoreApplication::setApplicationName("Recorder"); auto view = SailfishApp::createView(); auto context = view->rootContext(); Recorder recorder; context->setContextProperty("recorder", &recorder); RecordingsModel sourceModel; sourceModel.setRecorder(&recorder); QSortFilterProxyModel recordingsModel; recordingsModel.setSourceModel(&sourceModel); recordingsModel.setSortRole(RecordingsModel::Modified); recordingsModel.setDynamicSortFilter(true); recordingsModel.sort(0, Qt::DescendingOrder); context->setContextProperty("recordingsModel", &recordingsModel); view->setSource(SailfishApp::pathTo("qml/harbour-recorder.qml")); view->show(); return app->exec(); }
void BackEnd::run() { if (!m_model.init()) {/* обработка */} m_proxyModel.setSourceModel(&m_model); m_imagesSelection.setModel(&m_model); m_engine.addImageProvider("ImageProvider", new ImageProvider(m_dataManager)); m_engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); auto rc = m_engine.rootContext(); rc->setContextProperty("backEnd", this); rc->setContextProperty("dataModelBE", &m_model); }
void StepperControl::setStepper(Stepper* step) { if (step) { stepper = step; auto ctx = control->rootContext(); ctx->setContextProperty("stepper", stepper); } }
void PhotosTab::HandleCollectionSelected (const QModelIndex& index) { auto rootCtx = ImagesView_->rootContext (); if (!rootCtx->contextProperty ("listingMode").toBool ()) { QMetaObject::invokeMethod (ImagesView_->rootObject (), "showImage", Q_ARG (QVariant, QUrl ())); rootCtx->setContextProperty ("listingMode", true); } rootCtx->setContextProperty ("collRootIndex", QVariant::fromValue (index)); SelectedID_.clear (); SelectedCollection_ = index.data (CollectionRole::ID).toString (); emit tabRecoverDataChanged (); }
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; auto root_context = engine.rootContext(); //game objects ScoreSystem mScore; GameManager mManager(&mScore); root_context->setContextProperty("ccManager", &mManager); root_context->setContextProperty("ccScore", &mScore); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
int main(int argc, char *argv[]) { #if defined(Q_OS_WIN) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QGuiApplication app(argc, argv); QQmlApplicationEngine engine; std::unique_ptr<Test> test( new Test ); auto context = engine.rootContext(); context->setContextProperty( "testCppClass", test.get() ); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }
/*! Set a the \a value of the \a name property on this context. */ void QDeclarativeContext::setContextProperty(const QString &name, const QVariant &value) { Q_D(QDeclarativeContext); if (d->notifyIndex == -1) d->notifyIndex = this->metaObject()->methodCount(); QDeclarativeContextData *data = d->data; if (data->isInternal) { qWarning("QDeclarativeContext: Cannot set property on internal context."); return; } if (!isValid()) { qWarning("QDeclarativeContext: Cannot set property on invalid context."); return; } if (data->engine) { bool ok; QObject *o = QDeclarativeEnginePrivate::get(data->engine)->toQObject(value, &ok); if (ok) { setContextProperty(name, o); return; } } if (!data->propertyNames) data->propertyNames = new QDeclarativeIntegerCache(data->engine); int idx = data->propertyNames->value(name); if (idx == -1) { data->propertyNames->add(name, data->idValueCount + d->propertyValues.count()); d->propertyValues.append(value); data->refreshExpressions(); } else { d->propertyValues[idx] = value; QMetaObject::activate(this, idx + d->notifyIndex, 0); } }
/*! Set a the \a value of the \a name property on this context. */ void QQmlContext::setContextProperty(const QString &name, const QVariant &value) { Q_D(QQmlContext); if (d->notifyIndex == -1) d->notifyIndex = QMetaObjectPrivate::absoluteSignalCount(&QQmlContext::staticMetaObject); QQmlContextData *data = d->data; if (data->isInternal) { qWarning("QQmlContext: Cannot set property on internal context."); return; } if (!isValid()) { qWarning("QQmlContext: Cannot set property on invalid context."); return; } if (data->engine) { bool ok; QObject *o = QQmlEnginePrivate::get(data->engine)->toQObject(value, &ok); if (ok) { setContextProperty(name, o); return; } } QV4::IdentifierHash<int> &properties = data->detachedPropertyNames(); int idx = properties.value(name); if (idx == -1) { properties.add(name, data->idValueCount + d->propertyValues.count()); d->propertyValues.append(value); data->refreshExpressions(); } else { d->propertyValues[idx] = value; QMetaObject::activate(this, d->notifyIndex, idx, 0); } }
void dos_qqmlcontext_setcontextproperty(::DosQQmlContext *vptr, const char *name, ::DosQVariant *value) { auto context = static_cast<QQmlContext *>(vptr); auto variant = static_cast<QVariant *>(value); context->setContextProperty(QString::fromUtf8(name), *variant); }
void Tasty::_init() { #ifdef QT_DEBUG static bool inited = false; Q_ASSERT(!inited); inited = true; auto now = QDateTime::currentMSecsSinceEpoch(); #endif Bayes::instance(this); _engine = new QQmlApplicationEngine(this); _settings = new Settings(this); _manager = _engine->networkAccessManager(); _pusher = new PusherClient(this); _dataCache = new TastyDataCache; _entryImageWidth = _settings->maxImageWidth(); _commentImageWidth = _entryImageWidth; Q_TEST(connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(_saveOrReconnect(Qt::ApplicationState)))); Q_TEST(connect(_manager, SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)), this, SLOT(_showNetAccessibility(QNetworkAccessManager::NetworkAccessibility)))); Q_TEST(connect(_pusher, SIGNAL(unreadChats(int)), this, SLOT(_setUnreadChats(int)))); Q_TEST(connect(_pusher, SIGNAL(unreadNotifications(int)), this, SLOT(_setUnreadNotifications(int)))); Q_TEST(connect(_pusher, SIGNAL(unreadFriendsEntry(int)), this, SLOT(_incUnreadFriendsEntries()))); QQuickStyle::setStyle("Material"); qmlRegisterType<FeedModel> ("org.binque.taaasty", 1, 0, "FeedModel"); qmlRegisterType<CalendarModel> ("org.binque.taaasty", 1, 0, "CalendarModel"); qmlRegisterType<CommentsModel> ("org.binque.taaasty", 1, 0, "CommentsModel"); qmlRegisterType<AttachedImagesModel>("org.binque.taaasty", 1, 0, "AttachedImagesModel"); qmlRegisterType<UsersModel> ("org.binque.taaasty", 1, 0, "UsersModel"); qmlRegisterType<MessagesModel> ("org.binque.taaasty", 1, 0, "MessagesModel"); qmlRegisterType<FlowsModel> ("org.binque.taaasty", 1, 0, "FlowsModel"); qmlRegisterType<TagsModel> ("org.binque.taaasty", 1, 0, "TagsModel"); qmlRegisterType<Entry> ("org.binque.taaasty", 1, 0, "TlogEntry"); qmlRegisterType<CalendarEntry> ("org.binque.taaasty", 1, 0, "CalendarEntry"); qmlRegisterType<Comment> ("org.binque.taaasty", 1, 0, "Comment"); qmlRegisterType<User> ("org.binque.taaasty", 1, 0, "User"); qmlRegisterType<Author> ("org.binque.taaasty", 1, 0, "Author"); qmlRegisterType<Tlog> ("org.binque.taaasty", 1, 0, "Tlog"); qmlRegisterType<Rating> ("org.binque.taaasty", 1, 0, "Rating"); qmlRegisterType<AttachedImage> ("org.binque.taaasty", 1, 0, "AttachedImage"); qmlRegisterType<Media> ("org.binque.taaasty", 1, 0, "Media"); qmlRegisterType<Notification> ("org.binque.taaasty", 1, 0, "Notification"); qmlRegisterType<Message> ("org.binque.taaasty", 1, 0, "Message"); qmlRegisterType<MessageBase> ("org.binque.taaasty", 1, 0, "MessageBase"); qmlRegisterType<Conversation> ("org.binque.taaasty", 1, 0, "Chat"); qmlRegisterType<Flow> ("org.binque.taaasty", 1, 0, "Flow"); qmlRegisterType<TextHandler> ("org.binque.taaasty", 1, 0, "TextHandler"); qmlRegisterType<Poster> ("org.binque.taaasty", 1, 0, "Poster"); qmlRegisterType<CachedImage>("ImageCache", 2, 0, "CachedImage"); auto root = _engine->rootContext(); root->setContextProperty("Tasty", this); root->setContextProperty("Settings", _settings); auto notifs = NotificationsModel::instance(this); root->setContextProperty("NotifsModel", notifs); auto friendActivity = NotificationsModel::friendActivity(this); root->setContextProperty("FriendActivityModel", friendActivity); auto chats = ChatsModel::instance(this); root->setContextProperty("ChatsModel", chats); auto cache = CacheManager::instance(_manager); cache->setMaxWidth(_settings->maxImageWidth()); cache->setAutoloadOverWifi(_settings->loadImagesOverWifi()); cache->setMaxLoadSize(_settings->maxLoadImageSize()); root->setContextProperty("Cache", cache); Q_TEST(QObject::connect(_settings, SIGNAL(loadImagesOverWifiChanged(bool)), cache, SLOT(setAutoloadOverWifi(bool)))); Q_TEST(QObject::connect(_settings, SIGNAL(maxLoadImageSizeChanged(int)), cache, SLOT(setMaxLoadSize(int)))); auto bayes = Bayes::instance(); root->setContextProperty("Bayes", bayes); auto trainer = bayes->trainer(); root->setContextProperty("Trainer", trainer); #ifdef Q_OS_ANDROID float density = 160; #else float density = 267; // test #endif double scale = density < 180 ? 1 : density < 270 ? 1.5 : density < 360 ? 2 : 3; root->setContextProperty("mm", density / 25.4); // N900: 1 mm = 10.5 px; Q10: 12.9 root->setContextProperty("pt", 1); root->setContextProperty("dp", scale); // N900: 1.5; Q10: 2 root->setContextProperty("sp", density / 160); // scaleable pixels root->setContextProperty("builtAt", QString::fromLatin1(__DATE__)); _engine->setBaseUrl(QStringLiteral("qrc:/qml/")); _engine->load(QUrl(QStringLiteral("main.qml"))); #ifdef QT_DEBUG auto ms = QDateTime::currentMSecsSinceEpoch() - now; qDebug() << "Started in" << ms << "ms"; #endif }