创建一个线程类SendThread继承QThread
//SendThread.h
#pragma once
#include <QThread>
class SendThread : public QThread
{
Q_OBJECT
public:
SendThread(QObject *parent);
~SendThread();
int Create(const char* filename);
void Destroy();
int GetStatus();
int GetProgress();
private:
//线程入口函数
void run();
private:
char m_filepath[128];
int m_filesize;//文件的总字节数
int m_bytesread;//读取并处理了多少字节
int m_status;//状态 0:未完成,1完成
};
//SendThread.cpp
#include "SendThread.h"
#include <QDebug>
SendThread::SendThread(QObject *parent)
: QThread(parent)
{
}
SendThread::~SendThread()
{
}
int SendThread::Create(const char* filename)
{
strcpy(m_filepath, filename);
m_filesize = 0;
m_bytesread = 0;
m_status = 0;
start();//运行线程
return 0;
}
void SendThread::Destroy()
{
wait();
}
int SendThread::GetStatus()
{
return m_status;
}
int SendThread::GetProgress()
{
if (m_filesize