代码拉取完成,页面将自动刷新
#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#define APP_ID "d21085fc"
#define APP_KEY "f8bfc7de014a41ef7e35db6c35fd0b39"
#define PACKAGE_NAME "cn.com.upush.develop.qt.test"
#define UPUSH_HOST "192.168.6.132"
#define UPUSH_PORT 5488
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QPalette pe;
pe.setColor(QPalette::WindowText, QColor("#F56C6C"));
ui->statusLabel->setPalette(pe);
ui->netComboBox->addItem("UDP");
ui->netComboBox->addItem("TCP");
ui->netComboBox->setCurrentIndex(0);
ui->hostEdit->setText(UPUSH_HOST);
ui->portEdit->setText(QString("%1").arg(UPUSH_PORT));
connect(this, &Widget::comitText, this, &Widget::onShowText);
m_client = new UPush2Client();
m_client->configUPush(PACKAGE_NAME, APP_ID, APP_KEY, this);
}
Widget::~Widget()
{
delete ui;
delete m_client;
}
void Widget::on_registerButton_clicked()
{
if(m_client->getStatus() == STATUS_LOGIN_SUCCEED){
return;
}
m_client->setNetworkType(ui->netComboBox->currentIndex());
m_client->registerUPush(ui->hostEdit->text().toStdString(), ui->portEdit->text().toInt());
}
void Widget::on_bindButton_clicked()
{
QString userId = ui->bindEdit->text();
if(!userId.isEmpty()){
m_client->bindUser(userId.toStdString());
}
}
void Widget::on_pauseButton_clicked()
{
m_client->pause();
}
void Widget::on_resumeButton_clicked()
{
m_client->resume();
}
void Widget::on_unregButton_clicked()
{
m_client->unregisterUPush();
}
void Widget::on_clearButton_clicked()
{
ui->textBrowser->clear();
}
void Widget::onShowText(const QString & msg)
{
ui->textBrowser->insertPlainText(msg);
ui->textBrowser->insertPlainText("\n");
}
void Widget::onPushToken(int code, const char* pushToken, const char* userId)
{
qDebug() << "onPushToken" << pushToken << code << userId;
if(code == 0){
if(userId != nullptr){
ui->bindEdit->setText(QString("%1").arg(userId));
}else{
ui->bindEdit->setText("");
}
emit comitText(QString("[onPushToken] %1").arg(pushToken));
}else{
emit comitText(QString("[onPushToken] %1").arg(code));
}
}
void Widget::onPush(char* data, uint64_t pushTime, bool isOfflineMsg)
{
qDebug() << "onPush" << data << pushTime << isOfflineMsg;
emit comitText(QString("[onPush] %1").arg(data));
}
void Widget::onUnregister()
{
qDebug() << "onUnregister";
emit comitText("[onUnregister]");
}
void Widget::onRegisteredOnAnotherDevice(const char* info)
{
qDebug() << "onRegisteredOnAnotherDevice" << info;
emit comitText(QString("[onRegisteredOnAnotherDevice] %1").arg(info));
}
void Widget::onRevoke(const char* data, uint64_t revokeTime)
{
qDebug() << "onRevoke" << data << revokeTime;
emit comitText(QString("[onRevoke] %1").arg(data));
}
void Widget::onBindUser(int status)
{
qDebug() << "onBindUser" << status;
emit comitText(QString("[onBindUser] %1").arg(status == 0 ? "success" : "fail"));
}
void Widget::onStatusChanged(int status)
{
qDebug() << "onStatusChanged" << status;
switch (status) {
case STATUS_INIT:
ui->statusLabel->setText("初始");
break;
case GET_CONNECT_ADDRESS:
ui->statusLabel->setText("取得连接地址");
break;
case GET_CONNECT_ADDRESS_FAIL:
ui->statusLabel->setText("取得地址失败");
break;
case STATUS_CONNECTING:
ui->statusLabel->setText("正在连接");
break;
case STATUS_CONN_FAIL:
ui->statusLabel->setText("连接失败");
break;
case STATUS_LOGINING:
ui->statusLabel->setText("正在登陆");
break;
case STATUS_LOGIN_SUCCEED:
ui->statusLabel->setText("登陆成功");
break;
case STATUS_LOGIN_FAIL:
ui->statusLabel->setText("登陆失败");
break;
case STATUS_CLOSING:
ui->statusLabel->setText("正在关闭");
break;
case STATUS_LOGOUTING:
ui->statusLabel->setText("正在注销");
break;
case STATUS_LOGOUT_FAIL:
ui->statusLabel->setText("注销失败");
break;
case STATUS_CLOSED:
ui->statusLabel->setText("已经关闭");
break;
case STATUS_LOGOUT:
ui->statusLabel->setText("已注销");
break;
default:
break;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。