Harmattan Booster for Qt Quick Applications: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
[[Category:Snippets]] | [[Category:Snippets]] | ||
[[Category:Developing with Qt]] | |||
[[Category:HowTo]] | |||
[[Category:Tools::QtCreator]] | |||
[toc align_right= | [toc align_right="yes" depth="3"] | ||
= Manually Enabling Harmattan Booster Library = | = Manually Enabling Harmattan Booster Library = | ||
Up until and including Qt Creator 2.3.0, the | Up until and including Qt Creator 2.3.0, the "Qt Quick Application" wizard doesn't make use of the Harmattan booster library. This has a negative impact on application startup time, and might even lead to problems when submitting the application to the Ovi store. | ||
''Qt Creator 2.3.1 (which is now included in the latest updates to the Qt SDK) already enables the booster by default! The instructions below are only for people who have already projects created with 2.3.0 or older, or are not willing to update for whatever reasons.'' | ''Qt Creator 2.3.1 (which is now included in the latest updates to the Qt SDK) already enables the booster by default! The instructions below are only for people who have already projects created with 2.3.0 or older, or are not willing to update for whatever reasons.'' | ||
Line 13: | Line 16: | ||
== Changes to main.cpp == | == Changes to main.cpp == | ||
Replace your main.cpp with following code (obviously replacing | Replace your main.cpp with following code (obviously replacing "YourApp" by the name of your app): | ||
<code> | <code> | ||
#include <QtGui/QApplication> | |||
#include <QtDeclarative/QDeclarativeView> | |||
#include <QtDeclarative/QDeclarativeEngine> | |||
#include <MDeclarativeCache> | |||
Q_DECL_EXPORT int main(int argc, char *argv[]) | Q_DECL_EXPORT int main(int argc, char *argv[]) | ||
{ | |||
QScopedPointer<QApplication> app(MDeclarativeCache::qApplication(argc, argv)); | |||
QScopedPointer<QDeclarativeView> view(MDeclarativeCache::qDeclarativeView()); | |||
view- | view->setSource(MDeclarativeCache::applicationDirPath() | ||
+ QLatin1String("/../qml/YourApp/main.qml")); | |||
QObject::connect(view- | QObject::connect(view->engine(), SIGNAL (quit()), view.data(), SLOT (close())); | ||
view- | view->showFullScreen(); | ||
app- | app->exec(); | ||
} | |||
</code> | |||
== Changes to .pro file == | == Changes to .pro file == | ||
Line 31: | Line 44: | ||
Add | Add | ||
<code> | <code> | ||
CONFIG += qdeclarative-boostable | |||
</code> | |||
to the .pro file, and don't forget to do a full recompile! | to the .pro file, and don't forget to do a full recompile! | ||
Line 39: | Line 54: | ||
Open YourApp_harmattan.desktop in the project directory, and change | Open YourApp_harmattan.desktop in the project directory, and change | ||
<code> | <code> | ||
Exec=/usr/bin/single-instance /opt/YourApp/bin/YourApp | |||
</code> | |||
to | to | ||
<code> | <code> | ||
Exec=/usr/bin/invoker —type=d -s /opt/YourApp/bin/YourApp | |||
</code> | |||
''Do you have questions, or suggestions? Raise them under http://developer.qt.nokia.com/forums/viewthread/9164'' | ''Do you have questions, or suggestions? Raise them under http://developer.qt.nokia.com/forums/viewthread/9164'' |
Revision as of 10:45, 25 February 2015
[toc align_right="yes" depth="3"]
Manually Enabling Harmattan Booster Library
Up until and including Qt Creator 2.3.0, the "Qt Quick Application" wizard doesn't make use of the Harmattan booster library. This has a negative impact on application startup time, and might even lead to problems when submitting the application to the Ovi store.
Qt Creator 2.3.1 (which is now included in the latest updates to the Qt SDK) already enables the booster by default! The instructions below are only for people who have already projects created with 2.3.0 or older, or are not willing to update for whatever reasons.
This page outlines the changes you can do by hand to the source code to enable the booster. However, by making these changes your application will not compile any more for other targets!
Changes to main.cpp
Replace your main.cpp with following code (obviously replacing "YourApp" by the name of your app):
#include <QtGui/QApplication>
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeEngine>
#include <MDeclarativeCache>
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(MDeclarativeCache::qApplication(argc, argv));
QScopedPointer<QDeclarativeView> view(MDeclarativeCache::qDeclarativeView());
view->setSource(MDeclarativeCache::applicationDirPath()
+ QLatin1String("/../qml/YourApp/main.qml"));
QObject::connect(view->engine(), SIGNAL (quit()), view.data(), SLOT (close()));
view->showFullScreen();
app->exec();
}
Changes to .pro file
Add
CONFIG += qdeclarative-boostable
to the .pro file, and don't forget to do a full recompile!
Changes to .desktop file
Open YourApp_harmattan.desktop in the project directory, and change
Exec=/usr/bin/single-instance /opt/YourApp/bin/YourApp
to
Exec=/usr/bin/invoker —type=d -s /opt/YourApp/bin/YourApp
Do you have questions, or suggestions? Raise them under http://developer.qt.nokia.com/forums/viewthread/9164