widget.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "widget.h"
  2. #include "./ui_widget.h"
  3. #include <QNetworkReply>
  4. #include <QNetworkAccessManager>
  5. #include <QNetworkRequest>
  6. #include <QTimer>
  7. #include <QNetworkProxy>
  8. #include <regex>
  9. #include <stdlib.h>
  10. #include "QtFtp.h"
  11. #include "spdlog/spdlog.h"
  12. #include "fmtlog.h"
  13. Widget::Widget(QWidget *parent)
  14. : QWidget(parent)
  15. , ui(new Ui::Widget)
  16. {
  17. ui->setupUi(this);
  18. m_curlFtp.setFtpIPAndPort("192.168.50.100", "21");
  19. m_curlFtp.setFtpUsernameAndPassword("microsoft", "19980714Lq");
  20. SPDLOG_INFO("***** Qt Library *****");
  21. }
  22. Widget::~Widget()
  23. {
  24. delete ui;
  25. }
  26. void Widget::on_pBtn_connect_clicked()
  27. {
  28. SPDLOG_INFO("点击了“连接按钮”");
  29. QString url = "ftp://192.168.50.100/SSD1/Picture/";
  30. QString username = "microsoft";
  31. QString password = "19980714Lq";
  32. std::vector<std::string> list;
  33. CurlFtp::listFiles(url.toStdString(), username.toStdString(), password.toStdString(), list);
  34. for(const std::string& filename : list)
  35. {
  36. SPDLOG_INFO("{}", filename);
  37. }
  38. FMTLOG_INFO("***** Curl Library *****");
  39. FMTLOG_INFO("{}","你好");
  40. }
  41. /* 使用Windows API进行编码转换 */
  42. char* G2U(const char* gb2312)
  43. {
  44. int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
  45. wchar_t* wstr = new wchar_t[len+1];
  46. memset(wstr, 0, len+1);
  47. MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);
  48. len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
  49. char* str = new char[len+1];
  50. memset(str, 0, len+1);
  51. WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
  52. if(wstr) delete[] wstr;
  53. return str;
  54. }
  55. void Widget::on_pBtn_downloadFile_clicked()
  56. {
  57. SPDLOG_INFO("点击了“下载文件”");
  58. std::vector<std::string> fileList;
  59. m_curlFtp.getFileList("/SSD1/Picture/", fileList);
  60. }
  61. void Widget::on_pBtn_downloadVideo_clicked()
  62. {
  63. SPDLOG_INFO("点击了“下载视频”");
  64. std::shared_ptr<QtFtp> ftp = std::make_shared<QtFtp>();
  65. ftp->setHostAndPort("192.168.50.100");
  66. ftp->setUserPasswd("microsoft", "19980714Lq");
  67. QString localPath = QApplication::applicationDirPath() + "/v1.mp4";
  68. ftp->getFile(localPath, "/SSD1/Video/v1.mp4");
  69. ftp->waitFinished(-1);
  70. if(ftp->getResult())
  71. {
  72. SPDLOG_INFO("下载成功");
  73. }
  74. else
  75. {
  76. SPDLOG_INFO("下载失败");
  77. }
  78. }