Skip to content

Instantly share code, notes, and snippets.

@cckwes
Last active December 14, 2015 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cckwes/5053643 to your computer and use it in GitHub Desktop.
Save cckwes/5053643 to your computer and use it in GitHub Desktop.
Tweak on the sailfishapplication to get rootContext working
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(Sailfish::createApplication(argc, argv));
//initialize the milk classes
MilkTask *mt = new MilkTask(qApp);
QScopedPointer<QDeclarativeView> view(Sailfish::createView());
//create the root context and set the context properties
QDeclarativeContext *rootContext = view->rootContext();
rootContext->setContextProperty("tasksModel", mt->getProxyModel());
//set the source file
Sailfish::setView(view.data(), "main.qml");
//show the view
Sailfish::showView(view.data());
}
QDeclarativeView *Sailfish::createView()
{
QDeclarativeView *view;
#ifdef HAS_BOOSTER
view = MDeclarativeCache::qDeclarativeView();
#else
view = new QDeclarativeView;
#endif
return view;
}
void Sailfish::setView(QDeclarativeView *view, const QString &file)
{
bool isDesktop = qApp->arguments().contains("-desktop");
QString path;
if (isDesktop) {
path = qApp->applicationDirPath() + QDir::separator();
#ifdef DESKTOP
view->setViewport(new QGLWidget);
#endif
} else {
path = QString(DEPLOYMENT_PATH);
}
view->setSource(QUrl::fromLocalFile(path + file));
}
QDeclarativeView *createView();
void setView(QDeclarativeView* view, const QString &);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment