I am developing an application for BB-10 using web service. In this I want to parse JSON in both the get and post methods and I want to check the Internet availability.
我正在使用Web服务开发BB-10应用程序。在这里我想在get和post方法中解析JSON,我想检查Internet的可用性。
How can I do this?
我怎样才能做到这一点?
4 个解决方案
#1
5
Check the Internet Availability using the below code
使用以下代码检查Internet可用性
bool app::isNetworkAvailable() {
QNetworkConfigurationManager netMgr;
QList<QNetworkConfiguration> mNetList = netMgr.allConfigurations(QNetworkConfiguration::Active);
return (mNetList.count() > 0 && netMgr.isOnline());
}
#2
1
My teacher created a qml component that shows if there is connection and what kind of connection it is (wifi, bluetooth, carrier etc). It also sends a signal when the connection status or the interface used has changed.
我的老师创建了一个qml组件,显示是否存在连接以及它是什么类型的连接(wifi,蓝牙,运营商等)。当连接状态或使用的接口发生变化时,它也会发送信号。
The code is hosted at github: https://github.com/rodrigopex/CheckInternetMicroSample
代码托管在github:https://github.com/rodrigopex/CheckInternetMicroSample
#3
0
1.HPP FILE
1.HPP文件
class controller : public QObject
{
Q_OBJECT
public:
controller(bb::cascades::Application *app);
public Q_SLOTS:
void sendRequest(const QString &countryID);
private Q_SLOTS:
void onFinished();
};
2.CPP FILE
2.CPP文件
void controller::sendRequest(const QString &countryID)
{
QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);
const QString queryUri = QString::fromLatin1("http://192.168.1.251:410/Mobile/Service1.svc/english/Category?CountryID=%1").arg(countryID);
QNetworkRequest request(queryUri);
QNetworkReply* reply = networkAccessManager->get(request);
bool ok = connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
Q_ASSERT(ok);
Q_UNUSED(ok);
}
void controller::onFinished()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200)
{
JsonDataAccess jda;
QVariantMap map = jda.loadFromBuffer(reply->readAll()).toMap();
QVariantList addresses = map["GetCategoryResult"].toList();
foreach(QVariant var, addresses) {
QVariantMap addressMap = var.toMap();
qDebug() << "CategoryName is " << addressMap["CategoryName"].toString();
qDebug() << "CategoryID is " << addressMap["CategoryID"].toString();
}
}
else {
qDebug() << "Server returned code " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
}
}
SEE FULL CODE HERE----> http://supportforums.blackberry.com/t5/Native-Development/webservice-help-json/m-p/2569953/highlight/false#M46724
在这里查看完整的代码----> http://supportforums.blackberry.com/t5/Native-Development/webservice-help-json/m-p/2569953/highlight/false#M46724
#4
0
1) You can check the internet available by the following method as per documentation:
1)您可以按照以下方法检查互联网:
bool QNetworkConfigurationManager::isOnline () const
bool QNetworkConfigurationManager :: isOnline()const
Returns true if the system is considered to be connected to another device via an active network interface; otherwise returns false.
如果系统被认为通过活动网络接口连接到另一个设备,则返回true;否则返回false。
2) As for the json bits, you could use the json parser in Qt 5 as follows:
2)对于json位,可以使用Qt 5中的json解析器,如下所示:
Qt中的JSON支持
It is simple enough to bundle Qt 5 againt your application, but it will hopefully available on the platform soon.
将Qt 5捆绑在您的应用程序中非常简单,但很快就可以在平台上使用它。
Qt 5 on BlackBerry 10 - Beyond the Myth
关于黑莓10的Qt 5 - 超越神话
Failing that, it would be very simple to backport those few classes to Qt 4.
如果做不到这一点,那么将这几个类反向移植到Qt 4将非常简单。
#1
5
Check the Internet Availability using the below code
使用以下代码检查Internet可用性
bool app::isNetworkAvailable() {
QNetworkConfigurationManager netMgr;
QList<QNetworkConfiguration> mNetList = netMgr.allConfigurations(QNetworkConfiguration::Active);
return (mNetList.count() > 0 && netMgr.isOnline());
}
#2
1
My teacher created a qml component that shows if there is connection and what kind of connection it is (wifi, bluetooth, carrier etc). It also sends a signal when the connection status or the interface used has changed.
我的老师创建了一个qml组件,显示是否存在连接以及它是什么类型的连接(wifi,蓝牙,运营商等)。当连接状态或使用的接口发生变化时,它也会发送信号。
The code is hosted at github: https://github.com/rodrigopex/CheckInternetMicroSample
代码托管在github:https://github.com/rodrigopex/CheckInternetMicroSample
#3
0
1.HPP FILE
1.HPP文件
class controller : public QObject
{
Q_OBJECT
public:
controller(bb::cascades::Application *app);
public Q_SLOTS:
void sendRequest(const QString &countryID);
private Q_SLOTS:
void onFinished();
};
2.CPP FILE
2.CPP文件
void controller::sendRequest(const QString &countryID)
{
QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);
const QString queryUri = QString::fromLatin1("http://192.168.1.251:410/Mobile/Service1.svc/english/Category?CountryID=%1").arg(countryID);
QNetworkRequest request(queryUri);
QNetworkReply* reply = networkAccessManager->get(request);
bool ok = connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
Q_ASSERT(ok);
Q_UNUSED(ok);
}
void controller::onFinished()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200)
{
JsonDataAccess jda;
QVariantMap map = jda.loadFromBuffer(reply->readAll()).toMap();
QVariantList addresses = map["GetCategoryResult"].toList();
foreach(QVariant var, addresses) {
QVariantMap addressMap = var.toMap();
qDebug() << "CategoryName is " << addressMap["CategoryName"].toString();
qDebug() << "CategoryID is " << addressMap["CategoryID"].toString();
}
}
else {
qDebug() << "Server returned code " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
}
}
SEE FULL CODE HERE----> http://supportforums.blackberry.com/t5/Native-Development/webservice-help-json/m-p/2569953/highlight/false#M46724
在这里查看完整的代码----> http://supportforums.blackberry.com/t5/Native-Development/webservice-help-json/m-p/2569953/highlight/false#M46724
#4
0
1) You can check the internet available by the following method as per documentation:
1)您可以按照以下方法检查互联网:
bool QNetworkConfigurationManager::isOnline () const
bool QNetworkConfigurationManager :: isOnline()const
Returns true if the system is considered to be connected to another device via an active network interface; otherwise returns false.
如果系统被认为通过活动网络接口连接到另一个设备,则返回true;否则返回false。
2) As for the json bits, you could use the json parser in Qt 5 as follows:
2)对于json位,可以使用Qt 5中的json解析器,如下所示:
Qt中的JSON支持
It is simple enough to bundle Qt 5 againt your application, but it will hopefully available on the platform soon.
将Qt 5捆绑在您的应用程序中非常简单,但很快就可以在平台上使用它。
Qt 5 on BlackBerry 10 - Beyond the Myth
关于黑莓10的Qt 5 - 超越神话
Failing that, it would be very simple to backport those few classes to Qt 4.
如果做不到这一点,那么将这几个类反向移植到Qt 4将非常简单。