10-25-2012 10:57 AM
Hello,
I've been struggling with this for some hours now. I followed the "dialogs" example available at github, so I successfully created a SystemPrompt (the dialog that lets the user to enter text, and accept / dismiss it). Strangely enough, in that example there's no use of the user input text. Do you know how can I get that text in my QML? Here you have some sample code I'm using:
My QML:
// Default empty project template
import bb.cascades 1.0
import bb.system 1.0
// creates one page with a label
NavigationPane {
id: navigationPane
Page {
attachedObjects: [
SystemPrompt {
id: prompt
title: qsTr("Enter a text for the label")
modality: SystemUiModality.Application
inputField.inputMode: SystemUiInputMode.Default
inputField.emptyText: "Label text..."
confirmButton.label: qsTr("Ok")
confirmButton.enabled: true
cancelButton.label: qsTr("Cancel")
cancelButton.enabled: true
onFinished: {
if (result == SystemUiResult.ConfirmButtonSelection) {
lab1.text = ????? // Here is where I don't know what to do
}
}
}
]
Container {
layout: StackLayout {}
Label {
id: lab1
text: "Label text"
objectName: "lab1"
textStyle.base: SystemDefaults.TextStyles.TitleText
horizontalAlignment: HorizontalAlignment.Center
}
Button {
text: "Update label"
horizontalAlignment: HorizontalAlignment.Center
topMargin: 150.0
onClicked: {
//_appUi.editLabel();
prompt.show();
}
}
}
}
}Don't forget to add this in your app .cpp or .hpp file:
#include <bb/system/SystemCredentialsPrompt> #include <bb/system/SystemDialog> #include <bb/system/SystemPrompt> #include <bb/system/SystemToast> #include <bb/system/SystemUiButton> #include <bb/system/SystemUiError> #include <bb/system/SystemUiInputField> #include <bb/system/SystemUiInputMode> #include <bb/system/SystemUiPosition> #include <bb/system/SystemUiResult>
and also don't forget to include these in your app .cpp file (probably not all of them are needed but just in case I'm leaving them here for the moment):
qmlRegisterType<bb::system::SystemUiButton>("bb.sy stem", 1, 0, "SystemUiButton");
qmlRegisterType<bb::system::SystemUiInputField>("b b.system", 1, 0, "SystemUiInputField");
qmlRegisterType<bb::system::SystemToast>("bb.syste m", 1, 0, "SystemToast");
qmlRegisterType<bb::system::SystemPrompt>("bb.syst em", 1, 0, "SystemPrompt");
qmlRegisterType<bb::system::SystemCredentialsPromp t>("bb.system", 1, 0, "SystemCredentialsPrompt");
qmlRegisterType<bb::system::SystemDialog>("bb.syst em", 1, 0, "SystemDialog");
qmlRegisterUncreatableType<bb::system::SystemUiErr or>("bb.system", 1, 0, "SystemUiError", "");
qmlRegisterUncreatableType<bb::system::SystemUiRes ult>("bb.system", 1, 0, "SystemUiResult", "");
qmlRegisterUncreatableType<bb::system::SystemUiPos ition>("bb.system", 1, 0, "SystemUiPosition", "");
qmlRegisterUncreatableType<bb::system::SystemUiInp utMode>("bb.system", 1, 0, "SystemUiInputMode", "");
qmlRegisterUncreatableType<bb::system::SystemUiMod ality>("bb.system", 1, 0, "SystemUiModality", "");
qRegisterMetaType<bb::system::SystemUiResult::Type >("bb::system::SystemUiResult::Type");
Many thanks,
Solved! Go to Solution.
10-25-2012 11:59 AM
If you scan ever so carefully through the docs, you'll stumble over https://developer.blackberry.com/cascades/referenc
So replace your ????? with inputFieldTextEntry() and you'll get the text you need.
10-25-2012 01:04 PM
Thanks Peter. I went a couple of times through the SystemPrompt documentation, but I didn't realize about this method. I think It's time to rest now... hehe
03-30-2013 07:54 AM - edited 03-30-2013 07:55 AM
If you scan ever so carefully through the docs, you'll stumble over https://developer.blackberry.com/cascades/referenc
Peter, what does the documentation say about working in C++? How do you retrieve the text value then?
03-30-2013 08:23 AM
Eir wrote:
Peter, what does the documentation say about working in C++? How do you retrieve the text value then?
This should work the same in C++. I don't generally use C++ so I can't advise further. Have you tried it? If you did and it's not working, please post specifics (preferably in a new thread since this one is answered, so relatively few people would see your question if you just add it here).
03-30-2013 09:21 AM
Thanks for the reply. I found my way through. I also don't use C++ regularly, thus I rely on the documentation, which in this case is incomplete, misleading and with errors in the code examples.