11-14-2012 09:40 AM - edited 11-14-2012 09:55 AM
I have a NavigationPane defined in QML. In my C++ class I create the NavigationPane and use setContextProperty in order to have access to the C++ class. However, when I try to use the context in QML inside the onCreationCompleted signal, the console outputs a "ReferenceError: Can't find variable: splashSample" error.
Code is as follows:
QML:
import bb.cascades 1.0
NavigationPane
{
id: navigationPane
Page
{
onCreationCompleted:
{
splashSample.splashScreenDone.connect(navigationPane.push(getS econdPage()))
}
Container
{
background: Color.Black
layout: DockLayout
{
}
ImageView
{
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
imageSource: "asset:///images/splash.png"
onTouch:
{
// show detail page when the button is clicked
var page = getSecondPage();
console.debug("pushing detail " + page)
navigationPane.push(page);
}
property Page secondPage
function getSecondPage()
{
if (! secondPage)
{
secondPage = secondPageDefinition.createObject();
}
return secondPage;
}
attachedObjects:
[
ComponentDefinition
{
id: secondPageDefinition
source: "main.qml"
}
]
}
}
}
}
cpp file:
SplashScreenSample::SplashScreenSample(bb::cascades::Application *app) : QObject(app) { QmlDocument *qml = QmlDocument::create("asset:///splash.qml").parent( this); AbstractPane *root = qml->createRootObject<AbstractPane>(); qml->setContextProperty("splashSample", this); app->setScene(root); // QTimer::singleShot(1000, this, SLOT(loadMainScreen())); } void SplashScreenSample::loadMainScreen() { emit splashScreenDone(); qDebug("****************************************** ************************"); }
hpp file:
#ifndef SplashScreenSample_HPP_
#define SplashScreenSample_HPP_
#include <QObject>
namespace bb { namespace cascades { class Application; }}
class SplashScreenSample : public QObject
{
Q_OBJECT
public:
SplashScreenSample(bb::cascades::Application *app);
virtual ~SplashScreenSample() {}
public Q_SLOTS:
void loadMainScreen();
Q_SIGNALS:
void splashScreenDone();
};
#endif /* SplashScreenSample_HPP_ */It seems that the alias "splashSample" is not accessible in the onCreationCompleted signal. Is this the case? Is there a way to connect to a signal when the QML document is created?
Many thanks.
Solved! Go to Solution.
11-14-2012 09:59 AM
11-14-2012 10:04 AM
11-14-2012 10:10 AM