Last active
December 14, 2015 07:49
-
-
Save cckwes/5053643 to your computer and use it in GitHub Desktop.
Tweak on the sailfishapplication to get rootContext working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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