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
Developer
Posts: 402
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Activity Indicator, Signals and C++

Can we review your suggestion?

 

In the main.qml, I would have only the following signal declarations:

 

    onRetreiveStarted: {
        dataLoadIndicator.start();
    }

    onRetreiveFinished: {
        dataLoadIndicator.stop();
    }

 

Then in the HTTPRead.hpp, I would have the following:

 

	Q_PROPERTY(bool start READ start WRITE start NOTIFY retreiveStarted)
	Q_PROPERTY(bool finish READ finish WRITE finish NOTIFY retreiveFinished)

 This is where the train goes off the track for me.

 

 When you say modify the signals to take a bool, then they delcaration would be.

 

signals:

	void retreiveStarted(bool);
	void retreiveFinished(bool);

 

Highlighted
Retired
Posts: 252
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10
My Carrier: Bell

Re: Activity Indicator, Signals and C++

That's correct, Bluenoser! Did it work for you?

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Developer
Posts: 402
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Activity Indicator, Signals and C++

  I am still a little confused.

 

  First I want to check something. In your post, you wanted me to declare

 

   Q_PROPERTY(bool start READ start WRITE start NOTIFY retreiveStarted)

    Q_PROPERTY(bool finish READ finish WRITE start NOTIFY retreiveFinished)

  Should the second Q_PROPERTY WRITE be start of finish?

 

  Now for the other questions.

 

  What should the declarations for the start and finish be? I guess I need to have a variable(s) defined.  Do I need to create a connect for the signal slot?

 

  Could someone please take my example and see if they can get it to work? Thanks in advance.

Developer
Posts: 402
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Activity Indicator, Signals and C++

Thanks for everyone's patience. I Rethought what I was trying to accomplish and it was more complicated than it needed to be using signals.

 

I didn't want to use a global in a C++ class so I decided to pass the pointer to the ActivityIndicator to the class via a set method. This way the class controls both the look and functionality of the ActivityIndicator. Here is the code:

 

QML

        // An activity indicator that will be shown when data is loaded
        ActivityIndicator {
            objectName: "dataLoadIndicator"
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
        }
    }

 Activity.cpp

Activity::Activity(bb::cascades::Application *app)
: QObject(app)
{
	m_QmlDocument = QmlDocument::create("asset:///main.qml").parent(this);
	m_root = m_QmlDocument->createRootObject<AbstractPane>();
    app->setScene(m_root);

    createHTTPRead();
}

void Activity::createHTTPRead()
{
	HTTPRead *httpReadData = new HTTPRead(this);
	m_QmlDocument->setContextProperty("_httpReadData", httpReadData);
	httpReadData->setIndicator(m_root->findChild<ActivityIndicator*>("dataLoadIndicator"));
	httpReadData->retreiveData();
}

 HTTPRead.hpp

public:

	void setIndicator(ActivityIndicator *indicator);

private:

	ActivityIndicator *m_activityIndicator;

};

 HTTPRead.cpp

HTTPRead::HTTPRead(QObject *parent)
	: m_reply(0)
{
	m_activityIndicator = 0;
    connect(&m_accessManager, SIGNAL(sslErrors(QNetworkReply *, const QList<QSslError> & )), this, SLOT(onSslErrors(QNetworkReply *, const QList<QSSLError> &)));

} void HTTPRead::httpFinished() { log("HTTP Finished. Retrieved Data!"); if (m_reply->error() == QNetworkReply::NoError) { log("Network Reply reports No Errors!"); int available = m_reply->bytesAvailable(); QString bytesAvailable = QString::number(available); log("Reply has " + bytesAvailable + " bytes."); } if(m_activityIndicator) { if(m_activityIndicator->isRunning()) { log("stop indicator"); m_activityIndicator->stop(); } } m_reply->deleteLater(); } void HTTPRead::onSSLErrors(QNetworkReply *reply, const QList<QSslError> &errors) { reply->ignoreSslErrors(errors); } void HTTPRead::retreiveData() { log("Retrieving Data!"); this->clear(); QString path = m_dataAddress; log("Data URL is " + path); m_reply = m_accessManager.get(QNetworkRequest(QUrl(path))); connect(m_reply, SIGNAL(finished()), this, SLOT(httpFinished())); if(m_activityIndicator) { if(!m_activityIndicator->isRunning()) { log("start indicator"); m_activityIndicator->start(); } } } void HTTPRead::setIndicator(ActivityIndicator *indicator) { m_activityIndicator = indicator; m_activityIndicator->setPreferredWidth(100); m_activityIndicator->setPreferredHeight(100); } void HTTPRead::log(const QString &msg) { std::cout << msg.toStdString() << std::endl; }