I am trying to make a sample Blackberry 10 Cascades app in C++, Qt, & QML in the QNX Momentics IDE, and run it in the Blackberry 10 Dev Alpha Simulator. When I start running it, I get the following error messages:
ApplicationPrivate::declarativeEngine: ERROR called from non-UI thread QThread(0x8067e48) ApplicationPrivate::declarativeEngine: Method called from non-UI thread
I have tried googling those error messages - but I only find a few links that actually apply to my situation - and the solutions for those problems don't seem to apply to me.
I know it's got something to do with me trying to call different classes from different qml documents. (Which is something I was having trouble with before - which is why I made this sample app in the first place - to see if I could figure out how to call different classes from different qml documents).
Here is the code of my sample app. There are 7 files (main.qml
, main.cpp
, app.cpp
, app.hpp
, Page2.cpp
, Page2.h
, Page2.qml
). I would much appreciate if anyone could help me solve this - because I am not really sure what I am doing wrong.
Thank you.
(I have taken out main.cpp
& reduced the code from the other 6 files to what I think are the key parts to this problem).
I know the problem has something to do with my Page2
class and the Page2.qml
file.
(I think the problem is that there is something I have to do to be able to call qt code from more than one qml files - and I just don't know what that is).
main.qml
:
import bb.cascades 1.0
//-- create one page with a label and text
Page {
content: Container {
Button {
text: "Page 2"
onClicked: app.goToPage2
}
}
}
from app.cpp
App::App()
{
qmlRegisterType<App>("GDLiteBB", 1, 0, "app");
qmlRegisterType<Page2>("GDLiteBB", 1, 0, "Page2");
QmlDocument *qml = QmlDocument::create("main.qml");
qml->setContextProperty("app", this);
AbstractPane *root = qml->createRootNode<AbstractPane>();
Application::setScene(root);
}
void App::goToPage2() {
Page2::getInstance();
}
from app.hpp
class App : public QObject
{
Q_OBJECT
public:
App();
Q_INVOKABLE void goToPage2();
};
Page2.cpp
QmlDocument * Page2::qml_ = QmlDocument::create("Page2.qml");
AbstractPane * Page2::root_ = qml_->createRootNode<AbstractPane>();
Label * Page2::label_ = root_->findChild<Label *>("label");
Page2::Page2() : QObject() {
++count_;
page2_ = this;
qml_->setContextProperty("Page2", this);
Application::setScene(root_);
}
Page2 *Page2::getInstance() {
return page2_ ? page2_ : new Page2();
}
void Page2::setLabel() {
label_->setText("This is page 2");
}
Page2.h
class Page2 : public QObject {
Q_OBJECT
static Page2 *page2_;
static unsigned int count_;
static bb::cascades::QmlDocument *qml_;
static bb::cascades::AbstractPane *root_;
static bb::cascades::Label *label_;
Page2();
public:
static Page2 *getInstance();
virtual ~Page2();
Q_INVOKABLE void setLabel();
};
Page2.qml
import bb.cascades 1.0
import GDLiteBB 1.0
Page {
content: Container {
Button {
text: "Set Label"
onClicked: Page2.setLabel()
}
Label {
objectName: "Label"
}
}
}