02-04-2013 03:06 AM - edited 02-04-2013 03:07 AM
Hello,
I am trying to run an example from this page(https://developer.blackberry.com/cascades/document
code as stated on that page:
CombineCppAndQml::CombineCppAndQml(bb::cascades::Application *app) : QObject(app) { QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(th is); AbstractPane *root = qml->createRootObject<AbstractPane>(); qmlRegisterType<QTimer>("my.library", 1, 0, "QTimer"); app->setScene(root); }
and this I have in the QML file:
// Default empty project template
import bb.cascades 1.0
import my.library 1.0
Page {
Label {
id: timerTestLabel
text: "Hello world"
attachedObjects: [
QTimer {
id: timer
interval: 1000
onTimeout :{
timerTestLabel.text = "Timer triggered"
}
}
]
}
onCreationCompleted: {
timer.start();
}
}but I get a blank screen when I try to run the application. Can someone spot what is wrong here? Maybe I have called:
qmlRegisterType<QTimer>("my.library", 1, 0, "QTimer") at a wrong place?? Thanks.
Solved! Go to Solution.
02-04-2013 03:23 AM
That's the example.
Page {
property alias labelText: label.text
Container {
Label {
id: label
text: "Label"
}
Button {
objectName: "button"
text: "Button"
}
}
}
At a first glance I see that the container is missing.
02-04-2013 04:54 AM
02-04-2013 05:15 AM
Ok, right. But the example works for me. I see the text "Hello world". And after a moment I see "Timer triggered".
02-04-2013 05:26 AM
02-04-2013 05:30 AM
If it does not run then there should be some error message in the console of Momentics. Or in the compiler output during compilation should be an error message.
02-04-2013 05:36 AM
02-04-2013 05:41 AM
What about removing all the QTimer code and just showing the Label. At least this should work.
Furthermore, you can debug the application. Set a break point and execute your code step by step to see where the error is.
02-04-2013 06:03 AM - edited 02-04-2013 06:04 AM
One problem I think is with the following line: If I remove this line: import my.library 1.0
from the QML file I manage to display *just* a Label. However, once I add that import line I get the blank screen I mentioned. Can I ask you where in your code do you add the: " qmlRegisterType<QTimer>("my.library", 1, 0, "QTimer");" line? Maybe that is causing the issues? thanks.
02-04-2013 06:25 AM
Hi
Can u please move qmlRegisterType<QTimer>("my.library", 1, 0, "QTimer"); to the very first line of the constructor
CombineCppAndQml::CombineCppAndQml(bb::cascades::Application *app) : QObject(app) { qmlRegisterType<QTimer>("my.library", 1, 0, "QTimer"); QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(th is); AbstractPane *root = qml->createRootObject<AbstractPane>(); app->setScene(root); }
_ Dishooom
Hope this helps ![]()