一、效果展示
二、代码展示
.h
#ifndef FRMCOUNTCODE_H
#define FRMCOUNTCODE_H
#include <QWidget>
namespace Ui {
class frmCountCode;
}
class frmCountCode : public QWidget
{
Q_OBJECT
public:
explicit frmCountCode(QWidget *parent = 0);
~frmCountCode();
private:
Ui::frmCountCode *ui;
QStringList listFile;
private:
void initForm();
bool checkFile(const QString &fileName);
void countCode(const QString &filePath);
void countCode(const QStringList &files);
void countCode(const QString &fileName, int &lineCode, int &lineBlank, int &lineNotes);
private slots:
void on_btnOpenFile_clicked();
void on_btnOpenPath_clicked();
void on_btnClear_clicked();
};
#endif // FRMCOUNTCODE_H
.cpp
#pragma execution_character_set("utf-8")
#include "frmcountcode.h"
#include "ui_frmcountcode.h"
#include "qfile.h"
#include "qtextstream.h"
#include "qfiledialog.h"
#include "qfileinfo.h"
#include "qdebug.h"
frmCountCode::frmCountCode(QWidget *parent) : QWidget(parent), ui(new Ui::frmCountCode)
{
ui->setupUi(this);
this->initForm();
on_btnClear_clicked();
}
frmCountCode::~frmCountCode()
{
delete ui;
}
void frmCountCode::initForm()
{
QStringList headText;
headText << "文件名" << "类型" << "大小" << "总行数" << "代码行数" << "注释行数" << "空白行数" << "路径";
QList<int> columnWidth;
columnWidth << 130 << 50 << 70 << 80 << 70 << 70 << 70 << 150;
int columnCount = headText.count();
ui->tableWidget->setColumnCount(columnCount);
ui->tableWidget->setHorizontalHeaderLabels(headText);
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget->setEditTriggers(QAbstractItemView::No