Picker destroyed properly QML
I wanted to destroy a selector component on one of my pages at its opening, he calls fine: timePicker12.destroy ();
But does not actually destroy correctly, it only removes the model and not the element itself, surely that defies the whole point of the destroy function?
I wanted to get rid of the selector and its expansion button completely, anyone get this? 1.30 API running on 10.3.1 device
Call remove() your parent container:
yourParentContainerName.remove (timePicker12)
Tags: BlackBerry Developers
Similar Questions
-
Hello, I am very new to C++ / QML development (I'm familiar with JAVA).
I try the simplest thing, create a named factorial function that takes a parameter (hard-coded) which displays the result on the screen when the application starts and displays the screen. Here is my code, please explain what I'm doing wrong. I'm not clear how everything together "fits".
Thanks a lot for the help of anyones!
ApplicationUI.cpp
#include "applicationui.hpp".
#include
#include
#includeusing namespace bb::cascades;
ApplicationUI::ApplicationUI():
QObject()
{Create the scene of active main.qml, the parent document is defined
to make sure that the document is destroyed properly stopped down.
QmlDocument * qml = QmlDocument::create("asset:///main.qml").parent(this);Create the root for the UI object
AbstractPane * root = qml->() createRootObject;
root-> setProperty ("labelText", factorial (5)); ERROR HERE (factorial was not declared in this scope)Root object created together as the stage of the application
Application::instance()-> setScene (root);
}chain of factorial (long n)
{
long years = 1;
for (long I = 2; I have<= n;="" ++i)="">=>
years = years * i;
If (SNA< 0)="">
Returns - 1;
}
}
Return QString::number (years);
}Application.HPP
#ifndef ApplicationUI_HPP_
#define ApplicationUI_HPP_#include
class MyCppObject;
Class ApplicationUI: public QObject
{
Q_OBJECT
public:
ApplicationUI();Virtual ~ ApplicationUI() {}
String factorial (long n) () / /ERROR HERE ('string' is not a type, without return, based on non-void return)};
#endif / * ApplicationUI_HPP_ * /.
hand. QML
import bb.cascades 1.4
{Page}
property alias labelText: label.text
{Of container
{Label
ID: label
text: "Label".
}Button {}
objectName: 'button '.
text: "Button".
}
}
}the error message is "string does not name a type" because the string is not a type of data in c ++.
(and in java, it would be a String with a capital S)Use QString.
-
Request close does not correctly after the addition of SceneCover (QML)
Just added a SceneCover exposed to QML, wanted to change my implementation of shit,
Page { onCreationCompleted: { Application.setCover(sceneCover) } attachedObjects: [ // An Active Frame is a Scene Cover SceneCover { id: sceneCover content: Container { background: Color.create("Black") } },
#include "applicationui.hpp" //#include "ActiveFrameQML.h" #include
#include #include #include #include //#include "OrientationSensor.hpp" using namespace bb::cascades; ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { displayInformation = new si::blackberrydev::DisplayInformation; qmlRegisterType ("bb.cascades", 1, 2, "SceneCover"); qmlRegisterUncreatableType ("bb.cascades", 1, 2, "AbstractCover", ""); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Create root object for the UI qml->setContextProperty("display", displayInformation); AbstractPane *root = qml->createRootObject (); // Set created root object as the application scene Application::instance()->setScene(root); } Now, whenever the application closes, it does and does not correctly close until terminated manually:
It does not show this on the console but I'm not a clue what he is to me: "0x85ab510 error: must be attached to a control, no bb::cascades:QmlPage (0x85269a8).
Any Suggestions?
10.2 minimum API level targeting
I noticed that, while this works, attaching class SceneCover application directly gives an error of bps to the exit event.
To avoid this error, set the class of SceneCover via ComponentDefinition and attach it to the Application class.
I have attached a code snippet below:
onCreationCompleted: { Application.setCover(sceneCoverDef.createObject()) } attachedObjects: [ ComponentDefinition { id: sceneCoverDef SceneCover { content: Container { background: Color.create("#000000") Label { text: "hello" } } } } ]
Try and see if the error persists.
-
Hello guys I have this type of code in the following files do not know how to record the different colors, can someone help me?
Setting.HPP
#ifndef SETTINGS_HPP_ #define SETTINGS_HPP_ #include
class Settings: public QObject { Q_OBJECT public: Settings(); virtual ~Settings(); /** * This Invokable function gets a value from the QSettings, * if that value does not exist in the QSettings database, the default value is returned. * * @param objectName Index path to the item * @param defaultValue Used to create the data in the database when adding * @return If the objectName exists, the value of the QSettings object is returned. * If the objectName doesn't exist, the default value is returned. */ Q_INVOKABLE QString getValueFor(const QString &objectName, const QString &defaultValue); /** * This function sets a value in the QSettings database. This function should to be called * when a data value has been updated from QML * * @param objectName Index path to the item * @param inputValue new value to the QSettings database */ Q_INVOKABLE void saveValueFor(const QString &objectName, const QString &inputValue); }; Setting.cpp
#include "Settings.hpp" #include
Settings::Settings() { } QString Settings::getValueFor(const QString &objectName, const QString &defaultValue) { QSettings settings; // If no value has been saved, return the default value. if (settings.value(objectName).isNull()) { return defaultValue; } // Otherwise, return the value stored in the settings object. return settings.value(objectName).toString(); } void Settings::saveValueFor(const QString &objectName, const QString &inputValue) { // A new value is saved to the application settings object. QSettings settings; settings.setValue(objectName, QVariant(inputValue)); } Settings::~Settings() { } main.cpp
#include "applicationui.hpp" #include
#include #include #include "Settings.hpp" #include using namespace bb::cascades; QString getValue() { Settings settings; // use "theme" key for property showing what theme to use on application start return settings.getValueFor("theme", "primaryDropDown"); } Q_DECL_EXPORT int main(int argc, char **argv) { // update env variable before an application instance created qputenv("CASCADES_THEME", getValue().toUtf8()); Application app(argc, argv); // Create the Application UI object, this is where the main.qml file // is loaded and the application scene is set. ApplicationUI appui; // Enter the application main event loop. return Application::exec(); } Applicationui.HPP
#ifndef ApplicationUI_HPP_ #define ApplicationUI_HPP_ #include
namespace bb { namespace cascades { class LocaleHandler; } } class QTranslator; /*! * @brief Application UI object * * Use this object to create and init app UI, to create context objects, to register the new meta types etc. */ class ApplicationUI : public QObject { Q_OBJECT public: ApplicationUI(); virtual ~ApplicationUI() {} private slots: void onSystemLanguageChanged(); private: QTranslator* m_pTranslator; bb::cascades::LocaleHandler* m_pLocaleHandler; }; #endif /* ApplicationUI_HPP_ */ Applicationui.cpp
#include "applicationui.hpp" #include
#include #include #include #include "timer.hpp" #include "Settings.hpp" using namespace bb::cascades; ApplicationUI::ApplicationUI() : QObject() { // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); qmlRegisterType ("CustomTimer", 1, 0, "Timer"); bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); // This is only available in Debug builds Q_ASSERT(res); // Since the variable is not used in the app, this is added to avoid a // compiler warning Q_UNUSED(res); // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Create settings object and export it to qml Settings *settings = new Settings(); qml->setContextProperty("Settings", settings); // Create root object for the UI AbstractPane *root = qml->createRootObject (); // Set created root object as the application scene Application::instance()->setScene(root); // CustomTimer library } void ApplicationUI::onSystemLanguageChanged() { QCoreApplication::instance()->removeTranslator(m_pTranslator); // Initiate, load and install the application translation files. QString locale_string = QLocale().name(); QString file_name = QString("Vk10_%1").arg(locale_string); if (m_pTranslator->load(file_name, "app/native/qm")) { QCoreApplication::instance()->installTranslator(m_pTranslator); } } DropDown { id: primaryDropDown title: qsTr("Primary color") translationY: 5.0 Option { text: qsTr("Default"); value: 0 } Option { text: qsTr("Red"); value: Color.Red } Option { text: qsTr("Green"); value: Color.Green } Option { text: qsTr("Yellow"); value: Color.Yellow } Option { text: qsTr("Blue"); value: Color.Blue } Option { text: qsTr("Gray"); value: Color.Gray } onSelectedValueChanged: { Application.themeSupport.setPrimaryColor(primaryDropDown.selectedValue, primaryBaseDropDown.selectedValue) Settings.saveValueFor("primaryColor", primaryDropDown.selectedValue); } }
I do but not work
-
Notification when changes in the keyboard language
On two physical keyboard devices and devices to contact user can change the language or the keyboard (i.e. the input language). Is there a way to the running application to detect when such a change happens?
Any help is greatly appreciated.
I don't think that BPS has this info anywhere, here how get it instead of the PPS.
Don't forget to add some LIBS +=-lbb to your pro file.
You can reuse the class PpsWatch for any other purpose PPS incidentally, my app "File System" allows you to navigate to the folder MAP to discover the various objects available PPS, or you can also use your BlackBerry browser and copy - paste this url:
file:///PPS/
// applicationui.cpp #include "applicationui.hpp" #include
#include #include #include #include using namespace bb::cascades; ApplicationUI::ApplicationUI() : QObject() { // Don't forget to add LIBS += -lbb to your pro file m_ppsWatch = new PpsWatch("/pps/services/input/options", this); connect(m_ppsWatch, SIGNAL(logMessage(const QString&)), this, SLOT(onLogMessage(const QString&))); connect(m_ppsWatch, SIGNAL(ppsFileReady(const QVariantMap&)), this, SLOT(onPpsFileReady(const QVariantMap&))); // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); // This is only available in Debug builds Q_ASSERT(res); // Since the variable is not used in the app, this is added to avoid a // compiler warning Q_UNUSED(res); // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Create root object for the UI AbstractPane *root = qml->createRootObject (); // Set created root object as the application scene Application::instance()->setScene(root); } void ApplicationUI::onLogMessage(const QString& message) { qDebug() << message; } void ApplicationUI::onPpsFileReady(const QVariantMap& ppsMap) { if (ppsMap.contains("languages.active_lang_layouts")) { QVariantMap active_lang_layouts = ppsMap["languages.active_lang_layouts"].toMap(); QStringList locales = active_lang_layouts["locales"].toStringList(); qDebug() << "Language list used right now:" << locales; } } void ApplicationUI::onSystemLanguageChanged() { QCoreApplication::instance()->removeTranslator(m_pTranslator); // Initiate, load and install the application translation files. QString locale_string = QLocale().name(); QString file_name = QString("KeyboardLanguage_%1").arg(locale_string); if (m_pTranslator->load(file_name, "app/native/qm")) { QCoreApplication::instance()->installTranslator(m_pTranslator); } } // applicationui.hpp #ifndef ApplicationUI_HPP_ #define ApplicationUI_HPP_ #include
#include namespace bb { namespace cascades { class LocaleHandler; } } class QTranslator; /*! * @brief Application UI object * * Use this object to create and init app UI, to create context objects, to register the new meta types etc. */ class ApplicationUI : public QObject { Q_OBJECT public: ApplicationUI(); virtual ~ApplicationUI() {} private slots: void onLogMessage(const QString& message); void onPpsFileReady(const QVariantMap& ppsMap); void onSystemLanguageChanged(); private: QTranslator* m_pTranslator; bb::cascades::LocaleHandler* m_pLocaleHandler; PpsWatch* m_ppsWatch; }; #endif /* ApplicationUI_HPP_ */ /* * PpsWatch.cpp * * Created on: 2015-06-05 * Author: Roger */ #include
#include PpsWatch::PpsWatch(const QString& path, QObject *_parent) { emit logMessage("PpsWatch::PpsWatch()"); if (_parent) this->setParent(_parent); m_path = path; m_mapTitle = "@" + path.split("/").last(); m_ppsObject = new bb::PpsObject(path + "?wait,delta", this); connect(m_ppsObject, SIGNAL(readyRead()), this, SLOT(onPpsReadyRead())); if(!m_ppsObject->open(bb::PpsOpenMode::Subscribe)) { emit logMessage("Could not connect to " + path + " object: " + m_ppsObject->errorString()); } } PpsWatch::~PpsWatch() { emit logMessage("PpsWatch::~PpsWatch()"); delete m_ppsObject; m_ppsObject = NULL; } void PpsWatch::changePath(const QString& path) { emit logMessage("PpsWatch::changePath() " + path); if (m_path == path) { emit logMessage("Same path as before, return"); return; } m_path = path; m_mapTitle = "@" + path.split("/").last(); if(!m_ppsObject->close()) { emit logMessage("Could not disconnect from " + m_ppsObject->objectName() + " object: " + m_ppsObject->errorString()); } else { disconnect(m_ppsObject, SIGNAL(readyRead()), this, SLOT(onPpsReadyRead())); } m_ppsObject = new bb::PpsObject(path + "?wait,delta", this); connect(m_ppsObject, SIGNAL(readyRead()), this, SLOT(onPpsReadyRead())); if(!m_ppsObject->open(bb::PpsOpenMode::Subscribe)) { emit logMessage("Could not connect to " + path + " object: " + m_ppsObject->errorString()); } } void PpsWatch::onPpsReadyRead() { emit logMessage("PpsWatch::onPpsReadyRead()"); bool readOk; QByteArray data = m_ppsObject->read(&readOk); if(!readOk) { return; } bool decodeOk; const QVariantMap map = bb::PpsObject::decode(data, &decodeOk); if(!decodeOk) { return; } const QVariantMap ppsFile = map[m_mapTitle].toMap(); if (ppsFile.isEmpty()) { return; } emit ppsFileReady(ppsFile); } /* * PpsWatch.h * * Created on: 2015-06-05 * Author: Roger */ #ifndef PPSWATCH_H_ #define PPSWATCH_H_ #include
#include class PpsWatch : public QObject { Q_OBJECT public: PpsWatch(const QString& path, QObject *_parent = 0); virtual ~PpsWatch(); void changePath(const QString& path); private slots: void onPpsReadyRead(); private: bb::PpsObject* m_ppsObject; QString m_path; QString m_mapTitle; signals: void logMessage(const QString&); void ppsFileReady(const QVariantMap&); }; #endif /* PPSWATCH_H_ */ -
Previews not working do not under 10.3.1.2243?
I was about to publish a new version of my app, when I noticed that previews are no longer works since I upgraded my Z10 10.2.1 to 10.3.1.2243. At first, I thought that I must have inadvertently turned off instant previews in my phone settings, but they continue to work properly when an email, text, or BBM comes in. I also checked the App specific notification settings and everything looks good. The notification is save in the hub and scratch the alarm, but the preview is not displayed. It worked perfectly until I upgraded my OS device.
I'm doing something fancy in my application that allows me to build a single executable for OS 10.1 who can use the class of improved Notification of 10.2 if the application runs under 10.2 so I have to two generations. It worked fine under 10.2.1 but I was wondering if that ruse was causing my problem so I built a little app to Cascades coming fires a standard Notification 15 seconds after the start (which gives me enough time to switch to another application for the instant preview should be displayed). No matter if I have the build for Mac OS 10.2 or 10.3, in both cases the instant preview does not appear on my Z10. I can't test on a simulator since some sim versions are no notifications in the hub at all, and those that do will display previews not instant, even if the corresponding version of the ARM.
I wonder if anyone test this for me on a device running 10.3.1.2243. Simply create a "Hello World" application standard Cascades, add the bbplatform library, and then replace the following code for the support. Set the level of the API on 10.2 to use the Notification class that is expected to review instant.
I can't get my update until this is resolved. Thank you.
UPDATE: I forgot to mention that you must ask permission to notice too.
ApplicationUI.hpp
#ifndef ApplicationUI_HPP_ #define ApplicationUI_HPP_ #include
namespace bb { namespace cascades { class LocaleHandler; } } class QTranslator; /*! * @brief Application UI object * * Use this object to create and init app UI, to create context objects, to register the new meta types etc. */ class ApplicationUI : public QObject { Q_OBJECT public: ApplicationUI(); virtual ~ApplicationUI() {} private slots: void onSystemLanguageChanged(); void notify(); private: QTranslator* m_pTranslator; bb::cascades::LocaleHandler* m_pLocaleHandler; }; #endif /* ApplicationUI_HPP_ */ ApplicationUI.cpp
#include "applicationui.hpp" #include
#include #include #include #include #include using namespace bb::cascades; ApplicationUI::ApplicationUI() : QObject() { // prepare the localization m_pTranslator = new QTranslator( this ); m_pLocaleHandler = new LocaleHandler( this ); bool res = QObject::connect( m_pLocaleHandler, SIGNAL( systemLanguageChanged() ), this, SLOT( onSystemLanguageChanged() ) ); // This is only available in Debug builds Q_ASSERT( res ); // Since the variable is not used in the app, this is added to avoid a // compiler warning Q_UNUSED( res ); // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create( "asset:///main.qml" ).parent( this ); // Create root object for the UI AbstractPane *root = qml->createRootObject (); // Set created root object as the application scene Application::instance()->setScene( root ); QTimer::singleShot( 15000, this, SLOT( notify() ) ); } void ApplicationUI::onSystemLanguageChanged() { QCoreApplication::instance()->removeTranslator( m_pTranslator ); // Initiate, load and install the application translation files. QString locale_string = QLocale().name(); QString file_name = QString( "InstantPreviewTest_%1" ).arg( locale_string ); if ( m_pTranslator->load( file_name, "app/native/qm" ) ) { QCoreApplication::instance()->installTranslator( m_pTranslator ); } } void ApplicationUI::notify() { bb::platform::Notification* notification = new bb::platform::Notification(); notification->setTitle("Test Notification"); notification->setBody("This is a test notification"); notification->notify(); } You must allow instant previews with the NotificationDefaultApplicationSettings class (take a long breath).
http://developer.BlackBerry.com/native/reference/Cascades/bb__platform__notificationdefaultapplicati...Here is the code of a project without empty head, which includes the instant preview by default (sorry for the formatting, I'm on mobile):
Parameters of NotificationDefaultApplicationSettings;
settings.setPreview (NotificationPriorityPolicy::Allow);
Settings.Apply (); -
Hello
I have two files, CPC, applicationui.cpp, and message.cpp
I want to call the function in message.cpp of main.qml, but there is a problem. Help, please
applicationui.cpp ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); if(!QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()))) { // This is an abnormal situation! Something went wrong! // Add own code to recover here qWarning() << "Recovering from a failed connect()"; } // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); qml->setContextProperty("app",this); Message *msg = new Message(); qml->setContextProperty("messageObj",msg); // Create root object for the UI AbstractPane *root = qml->createRootObject
(); // Set created root object as the application scene app->setScene(root); } in main.qml
Button { text: "call function"; onClicked: { messageObj.myFunction(); } }
I said myFunction() as Q_INVOKABLE.
You better fasten your Message class to the QML and call it like that...
ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { qmlRegisterType
("custom.lib", 1, 0, "MessageClass"); then in the QML
Container { onCreationCompleted: { messageClass.callfunction(); } attachedObjects: [ MessageClass { id: messageClass } ] }
-
Hi all
When I try to call QMetaObject::invokeMethod at that time where I get error below.
"QMetaObject::invokeMethod: no such bb::cascades:QmlListView:detailNews (QVariant) method.
Down here I have attached a code please check and let me know how I can fix this issue?
ApplicationUI.cpp
NewsList.cpp
#include "applicationui.hpp" #include
#include #include #include #include #include #include using namespace bb::cascades; using namespace bb::data; QString getValueByKey(QVariant qVariant, QString qStrKey); QString getValueByKey(QVariant qVariant, QString qStrPath, QString qStrKey); QVariantList getListByPath(QVariant qVariant, QString qStrPath); ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app), root(0) { // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); // This is only available in Debug builds Q_ASSERT(res); // Since the variable is not used in the app, this is added to avoid a // compiler warning Q_UNUSED(res); // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. /* QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Create root object for the UI AbstractPane *root = qml->createRootObject (); // Set created root object as the application scene Application::instance()->setScene(root);*/ QmlDocument *qmlLoadingDialog = QmlDocument::create("asset:///LoadingDialog.qml").parent(this); dialogLoading = qmlLoadingDialog->createRootObject /** * Prepared by :- Umang Shah * **/#include "NewListItem.hpp" #include
#include #include #include #include #include #include #include using namespace bb::cascades; NewListItem::NewListItem(ListView * listView) : CustomControl(0){ this->listView = listView; QmlDocument *qml = QmlDocument::create("asset:///CustomRowNewsList.qml").parent(this); root = qml->createRootObject (); m_newsName = root->findChild It also seems that you have an incorrect class here. You are detailNews method is in your ApplicationUI class, but you are trying to call on the ListView, not your ApplicationUI object.
I recommend having a read through our documentation of signals and Slots , which should help you to achieve what you're trying to do.
-
Hi all!
I tried to use the following code to complete a call:
import bb.cascades 1.0 import bb.system 1.0 Page { Container { layout: DockLayout { } verticalAlignment: VerticalAlignment.Center horizontalAlignment: HorizontalAlignment.Center Button { id: callButton text: "End Call" onClicked: { phone.endCall("5555555555") } } } attachedObjects: [ Phone { id: phone } ] }
But it does not work.
What is missing?
I don't know if I need it to put the number of the incoming call.
Thanks for your help!
Kind regards!
Here is a complete application to work for you to play with :-)
hand. QML:
import bb.cascades 1.2 Page { Container { Label { // Localized text with the dynamic translation and locale updates support text: qsTr("Phone Test") + Retranslate.onLocaleOrLanguageChanged textStyle.base: SystemDefaults.TextStyles.BigText } Container { layout: StackLayout { orientation: LayoutOrientation.LeftToRight } TextField { id: txf_phone_number inputMode: TextFieldInputMode.PhoneNumber input.flags: TextInputFlag.AutoCapitalizationOff | TextInputFlag.AutoCorrectionOff | TextInputFlag.AutoPeriodOff | TextInputFlag.PredictionOff | TextInputFlag.SpellCheckOff } Button { text: "Make Call" onClicked: { app.makeCall(txf_phone_number.text); } } } Button { text: "End Call" onClicked: { app.endCall(); } } } }
applicationui. HPP:
#ifndef ApplicationUI_HPP_ #define ApplicationUI_HPP_ #include
#include #include namespace bb { namespace cascades { class Application; class LocaleHandler; } } class QTranslator; /*! * @brief Application object * * */ class ApplicationUI : public QObject { Q_OBJECT public: ApplicationUI(bb::cascades::Application *app); virtual ~ApplicationUI() { } Q_INVOKABLE void makeCall(QString msisdn); Q_INVOKABLE void endCall(); bb::system::phone::Phone* _phone; int _call_id; private slots: void onSystemLanguageChanged(); void onCallUpdated (const bb::system::phone::Call& call ); private: QTranslator* m_pTranslator; bb::cascades::LocaleHandler* m_pLocaleHandler; }; #endif /* ApplicationUI_HPP_ */ applicationui.cpp:
#include "applicationui.hpp" #include
#include #include #include using namespace bb::cascades; using namespace bb::system::phone; ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) , _phone(new bb::system::phone::Phone()) { // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); if(!QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()))) { // This is an abnormal situation! Something went wrong! // Add own code to recover here qWarning() << "Recovering from a failed connect()"; } // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); qml->setContextProperty("app", this); QObject::connect(_phone, SIGNAL(callUpdated(const bb::system::phone::Call&)), this, SLOT(onCallUpdated(const bb::system::phone::Call&))); // Create root object for the UI AbstractPane *root = qml->createRootObject (); // Set created root object as the application scene app->setScene(root); } void ApplicationUI::onSystemLanguageChanged() { QCoreApplication::instance()->removeTranslator(m_pTranslator); // Initiate, load and install the application translation files. QString locale_string = QLocale().name(); QString file_name = QString("PhoneTest_%1").arg(locale_string); if (m_pTranslator->load(file_name, "app/native/qm")) { QCoreApplication::instance()->installTranslator(m_pTranslator); } } void ApplicationUI::makeCall(QString msisdn) { qDebug() << "XXXX makeCall: " << msisdn; // reset call_id _call_id = -1; _phone->initiateCellularCall(msisdn); } void ApplicationUI::endCall() { qDebug() << "XXXX endCall"; if (_call_id != -1) { _phone->endCall(_call_id); } } void ApplicationUI::onCallUpdated(const bb::system::phone::Call& call ) { qDebug() << "XXXX onCallUpdated"; _call_id = call.callId(); qDebug() << "XXXX onCallUpdated - call_id=" << _call_id; } Permissions in bar - descriptor.xml:
control_phone access_phone PhoneTest.pro:
APP_NAME = PhoneTest CONFIG += qt warn_on cascades10 LIBS += -lbbsystem include(config.pri)
-
Ive has create a new class for listening to the phone call
/* * PhoneTools.cpp * * Created on: 27 Jul 2014 * Author: anditsung */ #include "PhoneTools.hpp" #include
#include using namespace bb::system::phone; PhoneTools::PhoneTools(QObject *parent) : QObject(parent) , mPhone(new bb::system::phone::Phone) { connect(mPhone, SIGNAL(callUpdated(const bb::system::phone::Call&)), SLOT(onCallUpdated(const bb::system::phone::Call&))); connect(mPhone, SIGNAL(callCommandResponseReceived(const bb::system::phone::CallCommandResponse&)), SLOT(onCallCommandResponseReceived(const bb::system::phone::CallCommandResponse&))); } void PhoneTools::onCallUpdated(const bb::system::phone::Call &call) { qDebug() << "HASDFADFASDFASDFDASFADSFDASF "; } void PhoneTools::onCallCommandResponseReceived(const bb::system::phone::CallCommandResponse &response) { qDebug() << "HASDFADFASDFASDFDASFADSFDASF "; } /* * PhoneTools.hpp * * Created on: 27 Jul 2014 * Author: anditsung */ #ifndef PHONETOOLS_HPP_ #define PHONETOOLS_HPP_ #include
#include class PhoneTools : public QObject { Q_OBJECT public: PhoneTools(QObject *parent = 0); private slots: void onCallUpdated(const bb::system::phone::Call&); void onCallCommandResponseReceived(const bb::system::phone::CallCommandResponse&); private: bb::system::phone::Phone *mPhone; }; #endif /* PHONETOOLS_HPP_ */ I use it like this
/* * Copyright (c) 2011-2014 BlackBerry Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "applicationui.hpp" #include
#include #include #include #include #include "PhoneTools.hpp" using namespace bb::cascades; ApplicationUI::ApplicationUI() : QObject() { // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); // This is only available in Debug builds Q_ASSERT(res); // Since the variable is not used in the app, this is added to avoid a // compiler warning Q_UNUSED(res); // initial load onSystemLanguageChanged(); PhoneTools phoneTools; // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Create root object for the UI AbstractPane *root = qml->createRootObject (); // Set created root object as the application scene Application::instance()->setScene(root); } void ApplicationUI::onSystemLanguageChanged() { QCoreApplication::instance()->removeTranslator(m_pTranslator); // Initiate, load and install the application translation files. QString locale_string = QLocale().name(); QString file_name = QString("TestPhoneManager_%1").arg(locale_string); if (m_pTranslator->load(file_name, "app/native/qm")) { QCoreApplication::instance()->installTranslator(m_pTranslator); } } his does not work. does not print do no debugging in the console
But if I use it like this
/* * Copyright (c) 2011-2014 BlackBerry Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "applicationui.hpp" #include
#include #include #include #include #include "PhoneTools.hpp" using namespace bb::cascades; using namespace bb::system::phone; ApplicationUI::ApplicationUI() : QObject() , mPhone(new bb::system::phone::Phone) { // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); // This is only available in Debug builds Q_ASSERT(res); // Since the variable is not used in the app, this is added to avoid a // compiler warning Q_UNUSED(res); // initial load onSystemLanguageChanged(); connect(mPhone, SIGNAL(callUpdated(const bb::system::phone::Call&)), SLOT(onCallUpdated(const bb::system::phone::Call&))); connect(mPhone, SIGNAL(callCommandResponseReceived(const bb::system::phone::CallCommandResponse&)), SLOT(onCallCommandResponseReceived(const bb::system::phone::CallCommandResponse&))); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Create root object for the UI AbstractPane *root = qml->createRootObject (); // Set created root object as the application scene Application::instance()->setScene(root); } void ApplicationUI::onCallUpdated(const bb::system::phone::Call &call) { qDebug() << "HELOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"; } void ApplicationUI::onCallCommandResponseReceived(const bb::system::phone::CallCommandResponse &callCommandResponse) { } void ApplicationUI::onSystemLanguageChanged() { QCoreApplication::instance()->removeTranslator(m_pTranslator); // Initiate, load and install the application translation files. QString locale_string = QLocale().name(); QString file_name = QString("TestPhoneManager_%1").arg(locale_string); if (m_pTranslator->load(file_name, "app/native/qm")) { QCoreApplication::instance()->installTranslator(m_pTranslator); } } He worked... do I did wrong in this?
Have you checked if the connect methods return true in the constructor PhoneTools?
Also, try to create the Phonetools object as follows
PhoneTools *tools = new PhoneTools(this);
-
Version number in the label (request for information)
Hey guys, I can't figure out how to make it work.
Here is my code:
application. UI
#include
... ... ... ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { ... ... //version info bb::ApplicationInfo appInfo; setProperty("versionNumber", appInfo.version()); } about. QML (where I try TSE it output)
... Page { ... property string versionNumber: "0.0.0" ... Label { id: lblversion text: qsTr("Version %1").arg(versionNumber) } }
That shows "0.0.0", but I want out of the real application version number.
Help would be appreciated.
Thank you
Here's the solution to this:
application.cpp:
... #include
... bb::ApplicationInfo appInfo; QString versionNumber = appInfo.version(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); QDeclarativePropertyMap* appProperties = new QDeclarativePropertyMap; appProperties->insert("name", QVariant(appInfo.title())); appProperties->insert("version", QVariant(appInfo.version())); appProperties->insert("description", QVariant(appInfo.description())); qml->setContextProperty("AppInfo", appProperties); QML:
text: qsTr("Version: %1").arg(AppInfo.version)
I would like to thank: knobtviker and anditsung
-
Simulating touch for Blackberry Z10 gestures
I want to simulate the gesture of touching the Z10 Blackberry. In the QML we keywords such as onClicked, onTriggered etc and there is action accordingly. But would it be possible without touching imitating the same onClicked, onTrigger actions?
Anyone can submit a code sample for the same where a touch gesture is needed for action and affect the same gesture is then simulated in the files/SRC or .qml?
It depends on how your code is structured and if you need to use a signal, or if you want to call the function directly. If your interface user is written in QML, but the logic is in C++ it can look like this.
QML:
Button { text: "Click Me!" onClicked: { _app.buttonClicked(); } }
And in your C++:
void ApplicationUI::simulateClick() { buttonClicked(); } void ApplicationUI::buttonClicked() { qDebug() << "CLICK!"; }
And don't forget to set the context property so that you can enter your QML calls C++:
// Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); qml->setContextProperty("_app", this);
-
Hi all
ListView in my app is not filling, here is the code snippet
ListView { id:sectionlistview objectName: "sectionlistview" ///dataModel: groupDataModel listItemComponents: [ ListItemComponent { id:row type: "item" CustomListItem { dividerVisible: true highlightAppearance: HighlightAppearance.Default Container{ opacity: 0.9 background: Color.create("#c0c0c0") layout: StackLayout { orientation: LayoutOrientation.TopToBottom } Label { text: ListItemData.name textStyle.base: myStyle.style textStyle.color: Color.create("#ffffff") } } } } ] }
void ApplicationUI::fetchData(){ listView = root->findChild
("sectionlistview"); model = new GroupDataModel(QStringList() << "name"); model->clear(); model->setGrouping(ItemGrouping::None); model->insert(dataName); listView->setDataModel(model); } dataName is a QVariantMap variable. The data are available in the variable, I checked that.
The following, almost identical to yours works for me. There are a few things in your code, which I don't see, so it is difficult to check every detail. First, create a new application and replace applicationui.cpp, applicationui.hpp and main.qml with my code and then test it. If it works, check if your code against mine. If not, let me know the device and the version of the OS that you are testing.
#ifndef ApplicationUI_HPP_ #define ApplicationUI_HPP_ #include
namespace bb { namespace cascades { class Application; class LocaleHandler; } } class QTranslator; /*! * @brief Application object * * */ class ApplicationUI : public QObject { Q_OBJECT public: ApplicationUI(bb::cascades::Application *app); virtual ~ApplicationUI() { } Q_INVOKABLE void fetchData(); private slots: void onSystemLanguageChanged(); private: QTranslator* m_pTranslator; bb::cascades::LocaleHandler* m_pLocaleHandler; }; #endif /* ApplicationUI_HPP_ */ applicationui. HPP
#include "applicationui.hpp" #include
#include #include #include #include #include using namespace bb::cascades; static AbstractPane *root = 0; ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); // This is only available in Debug builds Q_ASSERT(res); // Since the variable is not used in the app, this is added to avoid a // compiler warning Q_UNUSED(res); // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Create root object for the UI root = qml->createRootObject (); // Set created root object as the application scene app->setScene(root); qml->setContextProperty("app", this); } void ApplicationUI::onSystemLanguageChanged() { QCoreApplication::instance()->removeTranslator(m_pTranslator); // Initiate, load and install the application translation files. QString locale_string = QLocale().name(); QString file_name = QString("SupportListView_%1").arg(locale_string); if (m_pTranslator->load(file_name, "app/native/qm")) { QCoreApplication::instance()->installTranslator(m_pTranslator); } } void ApplicationUI::fetchData() { QVariantMap dataName; dataName["name"] = "Martin"; ListView* listView = root->findChild ((const QString) "sectionlistview"); GroupDataModel* model = new GroupDataModel(QStringList() << "name"); model->clear(); model->setGrouping(ItemGrouping::None); model->insert(dataName); listView->setDataModel(model); } applicationui.cpp
import bb.cascades 1.2 Page { Container { //Todo: fill me with QML Label { // Localized text with the dynamic translation and locale updates support text: qsTr("Hello World") + Retranslate.onLocaleOrLanguageChanged textStyle.base: SystemDefaults.TextStyles.BigText } Button { text: "Fetch Data" onClicked: { app.fetchData(); } } ListView { id: sectionlistview objectName: "sectionlistview" ///dataModel: groupDataModel listItemComponents: [ ListItemComponent { id: row type: "item" CustomListItem { dividerVisible: true highlightAppearance: HighlightAppearance.Default Container { opacity: 0.9 background: Color.create("#c0c0c0") layout: StackLayout { orientation: LayoutOrientation.TopToBottom } Label { text: ListItemData.name textStyle.base: myStyle.style textStyle.color: Color.create("#ffffff") } } } } ] } } }
hand. QML
Good luck!
Martin
-
Get the active navigation page in 10 blackberry app
I tried to reproduce this and also got the same error message. It seems that NavigationPane is not properly registered in the Cascades.
Added qmlRegisterType
() fixed it: ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); if(!QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()))) { // This is an abnormal situation! Something went wrong! // Add own code to recover here qWarning() << "Recovering from a failed connect()"; } // initial load onSystemLanguageChanged(); //-------------------------------------- qmlRegisterType
(); <---------------- ADDED //-------------------------------------- // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); qml->setContextProperty("_app", this); // Create root object for the UI AbstractPane *root = qml->createRootObject (); // Set created root object as the application scene app->setScene(root); } Another workaround solution is switching from QObject in settings:
Q_INVOKABLE void test(QObject *paneObj); ... void ApplicationUI::test(QObject *paneObj) { NavigationPane *pane = qobject_cast
(paneObj); Page *page = Page::create() .content(Label::create() .text("Test")); pane->push(page); } I have attached my test project (using NavigationPane * as a parameter) to the post.
UPD: created a JIRA ticket: https://www.blackberry.com/jira/browse/BBTEN-1801
-
"CustomTimer" module is not installed
I create a module with the name "CustomTimer", but if I run my project, main.qml not loaded, error 'CustomTimer module is not installed.
It's my applicationnui.cpp
/* * Copyright (c) 2011-2013 BlackBerry Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "applicationui.hpp" #include "timer.hpp" #include
#include #include #include using namespace bb::cascades; ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); // This is only available in Debug builds Q_ASSERT(res); // Since the variable is not used in the app, this is added to avoid a // compiler warning Q_UNUSED(res); // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Create root object for the UI AbstractPane *root = qml->createRootObject (); // Set created root object as the application scene app->setScene(root); // Register the Timer class in QML as part of version 1.0 of the // CustomTimer library qmlRegisterType ("CustomTimer", 1, 0, "Timer"); // ... } void ApplicationUI::onSystemLanguageChanged() { QCoreApplication::instance()->removeTranslator(m_pTranslator); // Initiate, load and install the application translation files. QString locale_string = QLocale().name(); QString file_name = QString("TraffictLight_%1").arg(locale_string); if (m_pTranslator->load(file_name, "app/native/qm")) { QCoreApplication::instance()->installTranslator(m_pTranslator); } } and this my timer.cpp
/* * timer.cpp * * Created on: May 14, 2014 * Author: Valdi */ #include
#include "timer.hpp" Timer::Timer(QObject* parent) : bb::cascades::CustomControl(), _timer(new QTimer(this)) { Q_UNUSED(parent); // If any Q_ASSERT statement(s) indicate that the slot // failed to connect to the signal, make sure you know exactly // why this has happened. This is not normal, and will cause your // app to stop working bool connectResult; // Since the variable is not used in the app, this is // added to avoid a compiler warning Q_UNUSED(connectResult); connectResult = connect(_timer, SIGNAL(timeout()), this, SIGNAL(timeout())); // This is only available in Debug builds. Q_ASSERT(connectResult); setVisible(false); } bool Timer::isActive() { return _timer->isActive(); } int Timer::interval() { return _timer->interval(); } void Timer::setInterval(int m_sec) { // If the timer already has the specified interval, do nothing if (_timer->interval() == m_sec) return; // Otherwise, set the interval of the timer and emit the // intervalChanged() signal _timer->setInterval(m_sec); emit intervalChanged(); } void Timer::start() { // If the timer has already been started, do nothing if (_timer->isActive()) return; // Otherwise, start the timer and emit the activeChanged() // signal _timer->start(); emit activeChanged(); } void Timer::stop() { // If the timer has already been stopped, do nothing if (!_timer->isActive()) return; // Otherwise, stop the timer and emit the activeChanged() // signal _timer->stop(); emit activeChanged(); } and this is my timer.hpp
/* * timer.hpp * * Created on: May 14, 2014 * Author: Valdi */ #ifndef TIMER_HPP_ #define TIMER_HPP_ #endif /* TIMER_HPP_ */ #include
#include class QTimer; class Timer : public bb::cascades::CustomControl { Q_OBJECT Q_PROPERTY(bool active READ isActive NOTIFY activeChanged) Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged) public: explicit Timer(QObject* parent = 0); bool isActive(); void setInterval(int m_sec); int interval(); public slots: void start(); void stop(); signals: void timeout(); void intervalChanged(); void activeChanged(); private: QTimer* _timer; }; Please help me, thanks before
You register your type after the staging, try to move the line to the top of the constructor qmlRegisterType().
Maybe you are looking for
-
Missing the bar of Composition
My publication is missing. I tried the Menu, the view, the toolbars, but I do not have a Bar for Composition. I checked the Options for Composition, and all is well. I tried everything I can think and have also talked with the local computer repair a
-
Wireless stall in Qosmio X 70-A
Hello I have a Qosmio X 70A & almost since I bought it there was issues with the wireless dropping out. I check my router etc. & it's all very well so there must be something with the laptop. I disabled the feature of saving power supply attached to
-
Vista cannot find the mouse USB - Satellite P100 - 434 PSPADE driver
* Need help to install a mouse optical usb on vista32 *. I have two mice, two optical usb, 1 wired and 1 wireless. They are the two plug-and-play so when to plug their vista must locate and install the right drivers automatically... it can't.Vista se
-
Re: Satellite A500 - 15 M - blue vertical line appears on the LCD screen
Hi - I turned on my laptop the other day (I have an A 500 - 15M) and I noticed a very thin dotted vertical blue line running through the centre-right of the screen of my computer, all the way up and down. I tried things like change the desktop theme,
-
SEL18200LE is not compatible with the detection of Phase AF on NEX-6 and NEX - 5R
Hello The SEL18200LE (a black) has recently published is not compatible with Phase detection. I just bought a. Do you have Sony will release a new firmware to detection of Phase for NEX - 6 / NEX - 5R? Thanks in advance. Eric