Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
Posts: 26
Registered: ‎02-22-2013
My Device: BlackBerry Z10
My Carrier: Telus

Cant figure out how to show dialog box

[ Edited ]

I want to show a simple dialog box with a couple lines of information in C++.

Here is what I have, but I can't even get the dialog box to show (I followed the sample from here and here ):

 

Dialog* myDialog = Dialog::create();
Container* myDialogContainer = Container::create();
myDialog ->setContent(myDialogContainer);
myDialog->open();

 If I do this, my app just freezes and the dialog doesn't show. I'm not sure if I'm missing something.

 

PS: I've added lbbmultimedia in .pro file.

Highlighted
Contributor
Posts: 11
Registered: ‎02-21-2013
My Device: BB10
My Carrier: Koodo

Re: Cant figure out how to show dialog box

wouldnt it be that either your missing this include

#include <bb/cascades/Dialog>

 or that the code is suppose to be like this

myDialog->setContent(myDialogContainer); //not myDialog ->set... theres a space on it

 

New Developer
Posts: 26
Registered: ‎02-22-2013
My Device: BlackBerry Z10
My Carrier: Telus

Re: Cant figure out how to show dialog box

[ Edited ]

So the solution I just figure out is dialog is not what I want. Dialog is just a transparent container on top of current page.

 

I want a SystemDialog, with prompt to say OK after info is shown.

 

If anyone wants to use this in the future, this is the code I am using for this: 

 

SystemDialog *dialog = new SystemDialog("OKay");

Regular Contributor
Posts: 76
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Cant figure out how to show dialog box

I have the same problem but i can't use a SystemDialog because i don't want any button in my dialog.

So i need a custom Dialog like this:

 

MessageDialog::MessageDialog() : Dialog()
{
    SpinningWheel = new ActivityIndicator();
    MainContainer = new Container();
    MainContainer->setHorizontalAlignment(HorizontalAlignment::Fill);
    MainContainer->setVerticalAlignment(VerticalAlignment::Fill);
    MainContainer->setLayout(new StackLayout() );


    BodyText = new Label();
    BodyText->setText(*(new QString("ABCDEFG") ) );


    MainContainer->add(BodyText);

    MainContainer->add(SpinningWheel);
   

    setContent(MainContainer);
}

 

 

Why the dialog is not showing when i run the Dialog:Smiley Surprisedpen() method ?

Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Cant figure out how to show dialog box

where are you calling

dialog.open()

 it doesnt work onCreationCompleted, you'll need to create a variable and adjust that, have a notifier setup to open the dialog when the variable is changed.

Regular Contributor
Posts: 76
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Cant figure out how to show dialog box

I call the open() in a class which is a QThread() derived and handle some operation. This class have a field of type MessageDialog.


If i use a SystemProgressDialog in the same class in place of the custom dialog the window is showed.
But as i mentioned above i need a custom Dialog not a SystemProgressDialog.

What is the variable that are you refferring ? What do you mean with "notifier setup" ?

Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Cant figure out how to show dialog box

by the variable i was meaning in qml

 

property bool showDialog

onShowDialogChanged: {
if (showDialog){
dialog.open()
}
}

 but it appears you're using c++, not too sure how to work with dialogs there but i do know that by default a custom dialog has no background, you'll need to provide one yourself, that could be causing your issue but not posotive

Regular Contributor
Posts: 76
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Cant figure out how to show dialog box

You are right slashkyle

 

That's the missing line:

 

MainContainer->setBackground( *(new ImagePaint( *(new Image("asset:///images/orange_background.png") ) , RepeatPattern::XY) ) );

Thank you !

Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Cant figure out how to show dialog box

Glad I could help out =)

 

Since you've got it working if you click options to the right and mark the post that solved your issue as a solution, it will let others know that the issue has been solved.

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Cant figure out how to show dialog box

Hi @bemipefe,

 

This code is leaking memory:

BodyText->setText(*(new QString("ABCDEFG") ) );

 Do not use the "* (new X)" construct. It creates new objects, but never deletes them.

 

This is more correct:

 

BodyText->setText(QString("ABCDEFG"));

 Even QString() is not needed as there is a default constructor:

BodyText->setText("ABCDEFG");

 

This will also leak memory:

MainContainer->setBackground( *(new ImagePaint( *(new Image("asset:///images/orange_background.png") ) , RepeatPattern::XY) ) );

A more correct way is:

MainContainer->setBackground(ImagePaint(Image("asset:///images/orange_background.png"));

C++ memory management is a complex topic, I suggest reading more on it. Memory management errors will cause the program to leak memory and eventually crash.

 


Andrey Fidrya, @zmeyc on twitter