创建一个线程类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 =
本文详细介绍了如何在QT中创建一个名为SendThread的线程类,该类继承自QThread。接着,展示了如何利用这个线程类来构建GUI应用程序SendDlg,从而实现多线程操作。在GUI类中,有效地调用了SendThread类,以实现并发处理。
订阅专栏 解锁全文

343

被折叠的 条评论
为什么被折叠?



