08-14-2012 03:56 AM
Hello,
I'm trying to implement a basic yes/no confirmation dialog.
I would use SystemDialog https://developer.blackberry.com/cascades/referenc
Can you help ?
Thanks,
Laurent
08-14-2012 02:13 PM
If invoking from C++:
Stuart
08-14-2012 02:30 PM
Oops sorry I would like a qml example...
08-14-2012 03:12 PM
Perhaps, you could use CustomDialog.
https://developer.blackberry.com/cascades/referenc
Under the QML side, you will need to make it visible somehow, such as:
Button {
text: "Pop"
layoutProperties: StackLayoutProperties {
horizontalAlignment: HorizontalAlignment.Center
}
onClicked: {
myCustomDialog.visible = true
}
}
and then handle the events, such as:
attachedObjects: [
CustomDialog {
id: myCustomDialog
content: Container {
Button {
text: "Yes"
onClicked: myCustomDialog.visible = false
}
Button {
text: "No"
onClicked: myCustomDialog.visible = false
}
}
}
]
Hope this helps.
08-14-2012 04:02 PM
08-14-2012 05:03 PM
That's great, let me know the results.
Cheers,
08-27-2012 04:56 AM
Following smacmartin's helpful reply, I have found that deriving a class from SystemDialog can be helpful. Use SystemDialogEx instead of SystemDialog and use showEx instead of show and you will have a self-deleting SystemDialog.
Of course, for those cases where you need to know how the dialog was dismissed, you can connect additional slots to the accepted and rejected signals.
Code:
SystemDialogEx::SystemDialogEx(QObject* parent)
: SystemDialog(parent)
{
}
SystemDialogEx::SystemDialogEx(const QString& confirmLabel, QObject* parent)
: SystemDialog(confirmLabel, parent)
{
}
SystemDialogEx::SystemDialogEx(const QString& confirmLabel, const QString& cancelLabel, QObject* parent)
: SystemDialog(confirmLabel, cancelLabel, parent)
{
}
SystemDialogEx::~SystemDialogEx()
{
}
void SystemDialogEx::showEx()
{
QObject::connect(this, SIGNAL(accepted()), this, SLOT(onDismissed()));
QObject::connect(this, SIGNAL(rejected()), this, SLOT(onDismissed()));
QObject::connect(this, SIGNAL(error(bb::system::SystemUiErrors::Type)), this, SLOT(onError(bb::system::SystemUiErrors::Type)));
show();
}
void SystemDialogEx::onDismissed()
{
deleteLater();
}
void SystemDialogEx::onError(bb::system::SystemUiErrors ::Type err)
{
deleteLater();
}
Jamie
09-17-2012 06:41 AM
Hi smacmartin,
I am also trying to display a dialog, followed steps you wrote for dialog creation.
in my App() constructor , I have written the following code.
Container *mContainer = root->findChild<Container*>("myContainer");
bb::system::SystemDialog *mSysDialog = new bb::system::SystemDialog("ok",
"cancel", mContainer);
mSysDialog->setTitle("Dialog");
mSysDialog->setBody("hello hello hello hello");
mSysDialog->show();
but on application execution dialog doesnot appear.
For simply creating a and displaying a dialog what else is required ?
Same problem occurs when I am using SystemToast class.
09-17-2012 03:15 PM
Hi MFSI,
I've made some quick tests here, you can try something like the samples below, m_mainPage comes from:
// The application Page is created from QML. m_mainPage = qml->createRootNode<Page>();
app.cpp
mSysDialog = new bb::system::SystemDialog("ok","cancel", m_mainPage);
mSysDialog->setTitle("Dialog");
mSysDialog->setBody("hello hello hello hello");
mSysToast = new bb::system::SystemToast(m_mainPage);
still on app.cpp
void App::onButton1Clicked(){
mSysDialog->show();
}
void App::onButton2Clicked(){
mSysToast->show();
}
app.hpp
bb::system::SystemDialog* mSysDialog; bb::system::SystemToast* mSysToast;
Hope this helps.
Cheers,
09-18-2012 03:41 AM
Thanks amarcon, for your reply.
But I want to clear one issue.
Is it necessary to connect dialog or toast with some other control and on emission of any signal from that control will invoke a slot that contains dialog's or toast's show() method ?
Can't we invoke show() method just after its(dialog's or toast's) initialization the way I did in my previous.
Also it wont affect whether a Page or a Container object acts as parent for dialog and toast . It will work for both.
Actually problem in my case was that I wasn't connecting Dialog or Toast with any other control.