-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.cpp
65 lines (61 loc) · 1.95 KB
/
utility.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "utility.h"
#include <QDebug>
#include <QSystemDeviceInfo>
#ifdef Q_OS_SYMBIAN
#include <akndiscreetpopup.h> //for discreet popup
#include <avkon.hrh> //..
#include <apgcli.h> //for launch apps
#include <apgtask.h> //..
#include <w32std.h> //..
#include <mgfetch.h> //for selecting picture
//#include <NewFileServiceClient.h> //for camera
#include <AiwServiceHandler.h> //..
#include <AiwCommon.hrh> //..
#include <AiwGenericParam.hrh> //..
#endif
Utility::Utility(QObject *parent) :
QObject(parent)
{
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));
}
Utility::~Utility()
{
manager->deleteLater();
}
void Utility::postHttp(const QString postMode,const QString postUrl,const QString postData)
{
//#ifdef Q_OS_SYMBIAN
//QTextCodec *codec = QTextCodec::codecForName("gbk");
//#else
QTextCodec *codec = QTextCodec::codecForName("gb2312");
//#endif
QByteArray array=codec->fromUnicode(postData);
QNetworkRequest request;
request.setUrl(QUrl(postUrl));
//request.setUrl(QUrl("http://www.9smart.cn"));
request.setRawHeader("User-Agent","Mozilla/5.0 (Nokia;Qt;MeeGo)");
if(postMode=="POST")
{
manager->post(request,array);
}else if(postMode=="GET"){
manager->get(request);
}else qDebug()<<"暂时没有支持其他种类的http请求";
}
void Utility::replyFinished(QNetworkReply *replys)
{
//qDebug()<<haha->errorString();
if(replys->error() == QNetworkReply::NoError)
{
QTextCodec *codec = QTextCodec::codecForName("gb2312");
QString string=codec->toUnicode(replys->readAll());
qDebug()<<"post return data:"<<string;
emit postOk(string);
}
}
//#ifdef Q_OS_SYMBIAN
void Utility::launchPlayer(const QString &url)
{
QDesktopServices::openUrl(QUrl(url));
}
//#endif