哈夫曼压缩Qt界面版

博主分享了如何在Qt环境中实现哈夫曼压缩,并创建了一个简单的用户界面。文章提供了相关源码,并提到在Qt IDE或VS中运行无误,但独立运行exe需要Qt库的dll文件。为了解决这个问题,博主提到了需要拷贝哪些dll文件到exe目录,并讨论了程序封包的可能性。
摘要由CSDN通过智能技术生成

之前写的哈夫曼压缩,想着加上界面,写了一天一个蹩脚的界面出来了。现在越来越喜欢Qt了,比MFC简单多了。

有些关于编译运行问题到文章末尾讲,先上源码。(推荐一个学Qt的网址点击打开链接

这是定义hfcom的头文件

#ifndef HFCOM_H
#define HFCOM_H

#include <QtWidgets/QMainWindow>
#include "ui_hfcom.h"
#include <qpushbutton.h>
#include <qobject.h>
#include <Windows.h>
#include <qstring.h>
#include <qfiledialog.h>
#include <qlineedit.h>
#include <qmessagebox.h>
#include <qstatusbar.h>
#include <qlabel.h>
#include <qicon.h>
#include "hf.h"

class hfcom : public QMainWindow
{
	Q_OBJECT

public:
	hfcom(QWidget *parent = 0);
	~hfcom();

private:
	QPushButton *button_open1;
	QLineEdit *path1;
	QPushButton *button_compress;
	QString *compressed_filename;
	QStatusBar *ps;
	void compress();
	void open_compressed_file();
	
	QPushButton *button_open2;
	QLineEdit *path2;
	QPushButton *button_decompress;
	QString *decompressed_filename;
	void decompress();
	void open_decompressed_file();
};

#endif // HFCOM_H


这是hfcom.cpp界面的实现都写在这里面了

#include "hfcom.h"

hfcom::hfcom(QWidget *parent) : QMainWindow(parent)
{
	this->resize(400, 247);
	this->setMinimumSize(450, 278);
	this->setMaximumSize(450, 278);
	this->setWindowIcon(QIcon("hflog.ico"));

	ps = new QStatusBar(this);
	ps->setGeometry(0,241,450,37);
	ps->showMessage(QString::fromLocal8Bit("ps:不支持中文路径和文件名"));

	button_open1 = new QPushButton(QString::fromLocal8Bit("打开文件"), this);
	button_open1->setGeometry(20, 40, 80, 37);
	path1 = new QLineEdit(this);
	path1->setReadOnly(true);
	path1->setGeometry(110, 40, 200, 37);
	button_compress = new QPushButton(QString::fromLocal8Bit("压缩"), this);
	button_compress->setGeometry(350, 40, 80, 37);
	

	button_open2 = new QPushButton(QString::fromLocal8Bit("打开文件"), this);
	button_open2->setGeometry(20, 140, 80, 37);
	path2 = new QLineEdit(this);
	path2->setReadOnly(true);
	path2->setGeometry(110, 140, 200, 37);
	button_decompress = new QPushButton(QString::fromLocal8Bit("解压"), this);
	button_decompress->setGeometry(350, 140, 80, 37);
	
	
	
	QObject::connect(button_compress, &QPushButton::clicked, this, &hfcom::compress);
	QObject::connect(button_decompress, &QPushButton::clicked, this, &hfcom::decompress);
	QObject::connect(button_open1, &QPushButton::clicked, this, &hfcom::open_compressed_file);
	QObject::connect(button_open2, &QPushButton::clicked, this, &hfcom::open_decompressed_file);
	//ui.setupUi(this);
}

hfcom::~hfcom()
{
}
void hfcom::compress()
{
	if( Compress((compressed_filename->toStdString()).c_str()) == true)
		QMessageBox::information(this, tr("Information"), QString::fromLocal8Bit("压缩成功"));
	else
		QMessageBox::information(this, tr("Information"), QString::fromLocal8Bit("压缩失败"));
}
void hfcom::decomp
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值