Symbian-Developers

The Official Developers Section => Symbian Software Development Discussions => The Developers Section => Qt Application Development => Topic started by: huellif on December 17, 2013, 01:51:43 am

Title: Dynamic loading in QtQuick
Post by: huellif on December 17, 2013, 01:51:43 am
QtQuick can be a slow thing :P
So you should try to increase the speed.
Most beginners put all dialogs, menus etc. into page.qml file, but you should load them dynamically.

Some people use this way:
(mainPage is the id of your page)
Code: [Select]
property Component __a: null
onClicked:{
if (!__Selector_widgets_classic) __a = Qt.createComponent("dialog.qml")
__a.createObject(mainPage)}}

a loader or something similar.

but all this Component properties and the repeating code slows down QtQuick.
Try this way instead (in your main.qml)

Code: [Select]
QtObject{
id:dialog;
property Component c:null;
function create(qmlfile){
c=Qt.createComponent(qmlfile);
c.createObject(mainPage)
}
}

now you can replace all loaders, components properties etc. in your whole project with:
Code: [Select]
dialog.create(dialog.qm)
(pages should load via PageStack and NOT via dynamic components) 
Title: Re: Dynamic loading in QtQuick
Post by: symster on December 17, 2013, 06:17:30 pm
In last line code you mean if i want to open query dialog,instead of using querydialog.open() i need to use dialog.create(querydialog.qml)
Title: Re: Dynamic loading in QtQuick
Post by: Allstar12345 on December 17, 2013, 07:05:14 pm
In last line code you mean if i want to open query dialog,instead of using querydialog.open() i need to use dialog.create(querydialog.qml)

Basically yeah.

But make sure that Dialog has
Code: [Select]
component.onCompleted:{open();} in it's code.
Title: Re: Dynamic loading in QtQuick
Post by: symster on December 17, 2013, 08:41:08 pm
 Err..."basically" confuse me but thanks anyway. :)
Title: Re: Dynamic loading in QtQuick
Post by: huellif on December 19, 2013, 04:57:19 am
here's an example:
Code: [Select]
import QtQuick 1.1
import com.nokia.symbian 1.1
QueryDialog{
id:aboutDialog
titleText:qsTr("About")
icon:"images/note_info.svg"
message:qsTr("Delight App v1.2.1\ncreated by Fabian\n\nthanks for your help with Qt/QML:\n- Paul\n- Anand\n- Dickson\n- Stefan\n- Maciej\n- Lucas\n\nthanks Marco for your help with native C++\n\nthanks Abdoul for your icons\n\nthanks for (your help with) MiniCMD:\n- Just Fancy\n\- Ashok\n- Eric\n- xCape\n- Marco")
acceptButtonText:qsTr("Back")
onAccepted:aboutDialog.destroy()
Component.onCompleted:open()}

if you have dialogs which can close without of buttons like (context)menus try this:
Code: [Select]
import QtQuick 1.1
import com.nokia.symbian 1.1
ContextMenu{
id:subMenu2
property bool __isClosing: false
MenuLayout{
MenuItem{
text:qsTr("Disable Application caching")
onClicked:dialog.create("Selector_cache_off.qml")}
MenuItem{
text:qsTr("Enable Contacts&Messaging")
onClicked:dialog.create("Selector_cache_some.qml")}}
Component.onCompleted:open()
onStatusChanged:{
if (status === DialogStatus.Closing) __isClosing = true
else if (status === DialogStatus.Closed && __isClosing) subMenu2.destroy()}}

credit for this way of dynamic deleting goes to Dickson

But make sure that Dialog has
Code: [Select]
component.onCompleted:{open();} in it's code.
{;} isn't needed.
Because of the slow javascript engine (compared to QtQuick 2), QDeclertive's parser, the limited ram and heap size, impact on size of your .exe (if you use QRC) less code is better
Title: Re: Dynamic loading in QtQuick
Post by: Motaz on December 19, 2013, 09:48:24 pm
Thank you huellif :)

I prefer to use this code to destroy the Dialog (It will keep the close animation  ;)):
Code: [Select]
Component.onCompleted: {
   open()
   isCreated = true
}

property bool isCreated: false
onStatusChanged: {
   if (isCreated && status === DialogStatus.Closed) {
       <DialogID>.destroy()
   }
}

As an alternative to this code:
Code: [Select]
onAccepted:aboutDialog.destroy()
Title: Re: Dynamic loading in QtQuick
Post by: huellif on December 19, 2013, 11:49:03 pm
Thank you huellif :)

;)

I prefer to use this code to destroy the Dialog (It will keep the close animation  ;)):
Code: [Select]
onStatusChanged: {
    if (status === DialogStatus.Closed)
        destroy()
}

that's a nice way :)


As an alternative to this code:
Code: [Select]
onAccepted:aboutDialog.destroy()

that's a easiest way of course :D
But (context) menus need the "onStatusChanged:"