#include "widget.h"
#include "./ui_widget.h"
#include#include#include#include#include#include#include#include#include#include#include#include#includeWidget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{ui->setupUi(this);
ftp = new QFtp;
if (ftp == nullptr) {qDebug()<< __func__<< ":No Mem alloc for ftp instance ... ... \n";
exit(1);
}
connect(ftp, SIGNAL(commandFinished(int, bool)), this,
SLOT(checkFTPstate(int, bool)));
connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)), this,
SLOT(progressBar_update(qint64, qint64)));
connect(this, SIGNAL(EmitError(QString,QString)), this, SLOT(errorMessage(QString,QString)));
connect(ftp,SIGNAL(stateChanged(int)),SLOT(FTPstate(int)));
connect(this,SIGNAL(EmitPutFile(QFileInfo)),this,SLOT(PutFile(QFileInfo)));
connect(ftp,SIGNAL(commandStarted(int)),this,SLOT(ftp_start(int)));
}
Widget::~Widget()
{delete ui;
}
void Widget::on_driver_path_sel_clicked()
{upgrade_file_path = QFileDialog::getOpenFileName(this,"選擇升級的驅(qū)動文件","./");
driver_file.setFile(upgrade_file_path);
ui->dirver_path->setText(this->upgrade_file_path);
}
void Widget::on_fpga_path_sel_clicked()
{upgrade_file_path =
QFileDialog::getOpenFileName(this, "選擇升級的FPGA文件", "./");
fpga_file.setFile(upgrade_file_path);
ui->fpga_path->setText(this->upgrade_file_path);
}
void Widget::on_database_path_sel_clicked()
{upgrade_file_path =
QFileDialog::getOpenFileName(this, "選擇升級的數(shù)據(jù)庫文件", "./");
database_file.setFile(upgrade_file_path);
ui->database_path->setText(this->upgrade_file_path);
}
void Widget::on_start_clicked()
{QString type;
if (ui->FILE_trans_type->currentText() == "FTP") {type = "ftp";
} else if (ui->FILE_trans_type->currentText() == "SFTP") {type="sftp";
}
std::vector>CheckList {std::make_pair(ui->driver_check,driver_file),std::make_pair(ui->fpga_check,fpga_file),std::make_pair(ui->database_check,database_file)};
for (auto i : CheckList) {if (i.first->isChecked()) { emit EmitPutFile(i.second);
}
}
}
void Widget::progressBar_update(qint64 readBytes, qint64 all) {auto percent = ((qreal)readBytes / all) * 100;
ui->upgrade_bar->setValue(percent);
ui->upgrade_label_status->setText(QString().fromStdString(std::to_string(readBytes/1024))+"/"+ QString().fromStdString(std::to_string(all/1024))+" KBytes");
if(percent == 100){}
}
void Widget::errorMessage(QString title,QString msg) {QMessageBox::information(this,title,msg);
}
void Widget::successMessage(QString msg) {QMessageBox::information(this,"成功提示",msg);
}
void Widget::checkFTPstate(int st, bool error) {if (ftp->currentCommand() == QFtp::Command::Put) {if (error) { emit EmitError("上傳失敗", ftp->errorString());
} else {this->setWindowTitle("上傳成功");
}
for (auto i = FILE_LIST.begin() ; i< FILE_LIST.end() ; i++) {if (i->second == st) { if (i->first != nullptr) {qDebug()<< "Delete "<< i->first->fileName()
<< " cmd id: "<< st;
delete i->first;
i->first = nullptr;
}
i = FILE_LIST.erase(i);
} else { ++i;
}
}
if (!ftp->hasPendingCommands()) { EmitError("升級提示","升級成功");
}
} else if (ftp->currentCommand() == QFtp::Command::ConnectToHost) {if (error) { emit EmitError("鏈接失敗", ftp->errorString());
} else { this->setWindowTitle("鏈接成功");
}
} else if (ftp->currentCommand() == QFtp::Command::Login) {if (error) { emit EmitError("登陸失敗", ftp->errorString());
} else { this->setWindowTitle("登陸成功");
}
} else if (ftp->currentCommand() == QFtp::Command::Close) {emit EmitError("鏈接提示", "斷開鏈接");
}
}
void Widget::FTPstate(int st) {if (st == QFtp::State::Connecting) {this->setWindowTitle("正在鏈接");
} else if (st == QFtp::State::Unconnected) {this->setWindowTitle("失去鏈接");
}else if(st == QFtp::State::LoggedIn){ this->setWindowTitle("登錄成功");
ui->login->setText("斷開鏈接");
}
}
void Widget::ftp_start(int){if(ftp->currentCommand() == QFtp::Put){ this->setWindowTitle("開始上傳");
}
}
void Widget::PutFile(QFileInfo FileName) {if(ftp->state() == QFtp::Connected || ftp->state() == QFtp::LoggedIn){file = new QFile;
if(file != nullptr){file->setFileName(FileName.absoluteFilePath());
if (file->open(QIODevice::ReadOnly)) { ui->upgrade_bar->setValue(0);
this->setWindowTitle("正在升級: " + FileName.fileName());
FILE_LIST.append(
std::make_pair(file, ftp->put(file, FileName.fileName())));
}}
}
}
void Widget::on_login_clicked()
{if(ui->login->text() == "斷開鏈接"){ftp->close();
ui->login->setText("鏈接板卡");
}else{QString hostinfo = ui->ip_addr->text();
ftp->connectToHost(hostinfo);
ftp->login("admin", "admin");
}
}
血淚教訓(xùn), QT5 ~ QT6 是一個大的版本跨越,NETWORK 的框架,和基類,變的要罵人了,找的QFtp 的模塊,改了變天源碼,卡在了, QString 的 ASSERT 上面,我就日了,回退到,5.15,
創(chuàng)新互聯(lián)長期為上千客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為樂東黎族企業(yè)提供專業(yè)的網(wǎng)站制作、成都網(wǎng)站建設(shè),樂東黎族網(wǎng)站改版等技術(shù)服務(wù)。擁有十多年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
雖然沒弄過QT之前,但是,看C++ 的代碼, 難怪,Linus 噴, 好多地方,真的挺惡心, 一坨坨的感覺
這算是一個DEMO 的版本
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧