11-16-2012 05:58 AM
Hi,
I am new in BB10 development and I try to make a simple app in C++.
Basically, three pages are stacked in a NavigationPane, each one contains a label and a button that pushes the next page. I based my code on the example "Creating a stack of screens" provided by BB10. My problem is that going from the first to second page works fine, but not from the second to the third. I also tried to put the creation of my pages in separated functions, and then now works anymore ![]()
So my problem is double : I'd like to know what is wrong in my functions and makes them not work, and what is wrong in the connection of the slot and signal of the second page's button for it not to load the third page.
My code :
Quizz.cpp
#include "Quizz.hpp"
Quizz::Quizz(bb::cascades::Application *app)
: QObject(app)
{
rootPane = new NavigationPane;
initPageAccueil();
initPageQuizz();
pageQuestion = new Page();
Container* questionContainer = new Container();
questionContainer->setLayout(StackLayout::create() );
Label* question = new Label();
question->setHorizontalAlignment(HorizontalAlignme nt::Center);
question->setVerticalAlignment(VerticalAlignment:: Center);
question->setText("Ceci est une question");
questionContainer->add(question);
Button* reponse = new Button();
reponse->setHorizontalAlignment(HorizontalAlignmen t::Center);
reponse->setVerticalAlignment(VerticalAlignment::B ottom);
reponse->setTopMargin(20.0f);
reponse->setText("Réponse");
questionContainer->add(reponse);
pageQuestion->setContent(questionContainer);
connect(commencer, SIGNAL(clicked()), this, SLOT(handleCommencerClicked()));
connect(quizz, SIGNAL(clicked()), this, SLOT(handleQuizzClicked()));
rootPane->push(pageAccueil);
Application::instance()->setScene(rootPane);
}
void Quizz::initPageAccueil()
{
Page* pageAccueil = new Page();
Container* accueilContainer = new Container();
accueilContainer->setLayout(StackLayout::create()) ;
Label* bienvenue = new Label();
bienvenue->setMultiline(true);
bienvenue->setHorizontalAlignment(HorizontalAlignm ent::Center);
bienvenue->setVerticalAlignment(VerticalAlignment: :Center);
bienvenue->setText("Bienvenue \n sur \n Quizz");
accueilContainer->add(bienvenue);
Button* commencer = new Button();
commencer->setHorizontalAlignment(HorizontalAlignm ent::Center);
commencer->setVerticalAlignment(VerticalAlignment: :Bottom);
commencer->setTopMargin(20.0f);
commencer->setText("Commencer");
accueilContainer->add(commencer);
pageAccueil->setContent(accueilContainer);
}
void Quizz::initPageQuizz()
{
Page* pageQuizz = new Page();
Container* quizzContainer = new Container();
quizzContainer->setLayout(StackLayout::create());
Label* choixQuizz = new Label();
choixQuizz->setHorizontalAlignment(HorizontalAlign ment::Center);
choixQuizz->setVerticalAlignment(VerticalAlignment ::Center);
choixQuizz->setText("Choisissez votre Quizz");
quizzContainer->add(choixQuizz);
Button* quizz = new Button();
quizz->setHorizontalAlignment(HorizontalAlignment: :Center);
quizz->setVerticalAlignment(VerticalAlignment::Bot tom);
quizz->setTopMargin(20.0f);
quizz->setText("Quizz 1");
quizzContainer->add(quizz);
pageQuizz->setContent(quizzContainer);
}
void Quizz::handleCommencerClicked()
{
rootPane->push(pageQuizz);
}
void Quizz::handleQuizzClicked()
{
rootPane->push(pageQuestion);
}
Quizz.h
#ifndef Quizz_HPP_
#define Quizz_HPP_
#include <QObject>
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/NavigationPane>
#include <bb/cascades/Page>
#include <bb/cascades/Container>
#include <bb/cascades/StackLayout>
#include <bb/cascades/StackLayoutProperties>
#include <bb/cascades/DockLayout>
#include <bb/cascades/Label>
#include <bb/cascades/Button>
namespace bb { namespace cascades { class Application; }}
using namespace bb::cascades;
/*!
* @brief Application pane object
*
*Use this object to create and init app UI, to create context objects, to register the new meta types etc.
*/
class Quizz : public QObject
{
Q_OBJECT
public:
Quizz(bb::cascades::Application *app);
virtual ~Quizz() {}
public slots:
void handleQuizzClicked();
void handleCommencerClicked();
private:
NavigationPane* rootPane;
Page* pageAccueil;
Container* accueilContainer;
Label* bienvenue;
Button* commencer;
Page* pageQuizz;
Container* quizzContainer;
Label* choixQuizz;
Button* quizz;
Page* pageQuestion;
void initPageAccueil();
void initPageQuizz();
};
#endif /* Quizz_HPP_ */ That's a long post
thanks in advance for your help and for reading me.
11-16-2012 10:48 AM
Well good news : I've just found the solution for the functions thing, but handling the second signal to push the third page when clicking on the second page's button is still a problem, so if anybody has an idea !
11-16-2012 10:55 AM
Annnnnnd it's gone, no more problem !