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: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL
Accepted Solution

The registration page over PHP

[ Edited ]

ive tried 2 weeks and didnt get work at all

ive done this qml page

regpage.png

when i clicked register, it should post paramater of fullname, email and password

the parameter should send to this url http://www.rws.rajaspot.com/rs_usermanagementclient.php

and if success it should show at this url http://www.rws.rajaspot.com/rs_userclient.php

it should use the HTTP request method post but i dont know the spesific code.

 

i dont know the "bridge" for sent the parameters to usermanagementclient

can u give the full code of CPP and HPP or QML ??

i tried many" ways but still, didnt work

 

"here's the parameter

fullname : fullName

email : email

password : password"

 

thanks

Developer
Posts: 232
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: The registration page over PHP

Here yo are sample (not good, but works) Smiley Wink

 

const QUrl url("https://masburti.pl/login.php");

QNetworkRequest request(url);
QNetworkAccessManager *mAccessManager;
mAccessManager = new QNetworkAccessManager(this);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

// Convert to string
QByteArray byteArrayObject;
byteArrayObject.append("&login="+login);
byteArrayObject.append("&passwd="+passwd);

// For your "Content-Length" header
QByteArray postDataSize = QByteArray::number(byteArrayObject.size());
request.setHeader(QNetworkRequest::ContentLengthHeader, QString(postDataSize).toUtf8());

QNetworkReply* reply = mAccessManager->post(request, byteArrayObject);
bool ok = connect(reply, SIGNAL(finished()), this, SLOT(onLoginEnd()));
Q_ASSERT(ok);
Q_UNUSED(ok);

 

All time online Smiley Very Happy
Developer
Posts: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL

Re: The registration page over PHP

@ (25 filip) : so that code, so this is for my for exampe : registrationpage.cpp or in my qml?

Developer
Posts: 232
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: The registration page over PHP

You need to put this code to your CPP file, but firstly I recommend you to read a little about communication between QML and C++ Smiley Wink
All time online Smiley Very Happy
Developer
Posts: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL

Re: The registration page over PHP

@26filip : thats the hard part, the connection qml and c++, is there any quick guide or sample that examine all those connection? thank u verymuch btw Smiley Happy

Developer
Posts: 232
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: The registration page over PHP

Developer
Posts: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL

Re: The registration page over PHP

i still dont understand, can u give the code example to connect between .cpp,.hpp, and main.qml the username and password?

i rather see the example than read, i dont understand

 

Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: The registration page over PHP

[ Edited ]

Just create an Q_INVOKABLE or public slots function in your app class.

for example:

Q_INVOKABLE
void myNamefunction(const QString &fullname, const QString &email, const QString &password);

 then set context property for QML as docs says (point to your class)

qml->setContextProperty("MyApp", this);

 and finally you can call the function from QML like this

MyApp.myNameFunction("fullname", "email", "password")

 Smiley Wink

 



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Highlighted
Developer
Posts: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL

Re: The registration page over PHP

[ Edited ]

already implement but still some errors

heres my complete CCP HPP and QML

 

REGISTER.HPP

 

//REGISTER.HPP

#ifndef REGISTER_HPP_
#define REGISTER_HPP_

#include <QObject>

namespace bb
{
    namespace cascades
    {
        class Application;
        class LocaleHandler;
    }
}

class QNetworkAccessManager;
class QTranslator;

class Register : public QObject
{
    Q_OBJECT
public:
    Register(bb::cascades::Application *app);
    virtual ~Register() { }

public Q_SLOTS:
    void post(const QString &fullName, const QString &email, const QString &password);

Q_SIGNALS:
    void complete(const QString &info);

private Q_SLOTS:
    void postFinished();

private:
    QNetworkAccessManager* m_networkAccessManager;
};


#endif /* REGISTER_HPP_ */

 REGISTER.CPP

#include "register.hpp"

#include <QDebug>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QSslConfiguration>
#include <QUrl>
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

using namespace bb::cascades;

Register::Register(bb::cascades::Application *app)
    : QObject(app)
    , m_networkAccessManager(new QNetworkAccessManager(this))
{

	QmlDocument *qml = QmlDocument::create("asset://Registerpage.qml").parent(this);


	qml->setContextProperty("MyApp",this);
	AbstractPane *root = qml ->createRootObject<AbstractPane>();
	app->setScene(root);

}
//! [0]

void Register::post(const QString &fullName, const QString &email, const QString &password)
{
	QNetworkAccessManager connection;

	QUrl url("http://www.rws.rajaspot.com/rs_usermanagementclient.php");
    QNetworkRequest req(url);

    QByteArray postParameters;

    postParameters += fullName;
    postParameters += email;
    postParameters += password;

    QNetworkReply* reply = connection.post(req, postParameters);
    bool ok = connect(reply, SIGNAL(finished()), this, SLOT(postFinished()));
    Q_ASSERT(ok);
    Q_UNUSED(ok);
}

/**
 * PostHttp::onGetReply()
 *
 * SLOT
 * Read and return the http response from our http post request
 */
void Register::postFinished()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    /* QString response;
    if (reply) {*/
        if (reply->error() == QNetworkReply::NoError) {
        	QString result = reply->readAll();
            /*const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer(reply->readAll());
                response = QString::fromUtf8(buffer);
            }*/
        } else {
            int errorCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
            qDebug() << errorCode << endl << reply ->errorString();
        }

        reply->deleteLater();
    }

 MAIN QML

 Button{
            id : button
            text : "Register"
            onClicked: {
               if(Myapp.Post((tf1.text,tf2.text,tfpass.text))){
                   
               }
            }
            horizontalAlignment: HorizontalAlignment.Center
        }

 but myapp.post still cannot call from my register.cpp

how do i fix this? thanks

Developer
Posts: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL

Re: The registration page over PHP

anyone can help me? thanks