QT 杀毒软件(课设)
- 开发语言:C++
- 开发工具:Qt Creator (QT5)
杀毒软件功能要求
- 病毒特征库管理(可增删查改病毒特征库)
- U盘扫描(U盘插入进行扫描)
- 安全运行程序(检索病毒库,如发现是病毒禁止运行)
- 指定磁盘扫描病毒
部分源码
class VirusScanWnd : public QWidget
{
Q_OBJECT
public:
VirusScanWnd(QWidget *parent = nullptr);
~VirusScanWnd();
protected:
void init();
LeftButton *addOneLeftButton(const QString &iconPath, const QString &text, const QString &tooltip, int childIndex);
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
protected slots:
void slotLeftButtonClicked(int childIndex);
void slotSetFeatureCode(const QJsonObject ¶);
void slotKillVirus(const QJsonObject ¶);
void slotKillVirusWndQuit();
void slotFeatureCodeDefined(const QJsonObject ¶);
void slotNewUDiskInsert(const QString &uDiskName);
signals:
void sigDiskChanged();
void sigNewUDiskInsert(const QString &uDiskName);
void sigKillUDisk(const QString &uDiskName);
private:
Ui::VirusScanWnd *ui;
QStringList diskList_;
};
VirusScanWnd::VirusScanWnd(QWidget *parent)
: QWidget(parent)
, ui(new Ui::VirusScanWnd)
{
ui->setupUi(this);
this->setFixedSize(this->size());
// this->setWindowFlags(Qt::FramelessWindowHint);
init();
}
/**
* @brief VirusScanWnd::~VirusScanWnd
*/
VirusScanWnd::~VirusScanWnd()
{
delete ui;
}
/**
* @brief init
*/
void VirusScanWnd::init()
{
gAppDirPath = qApp->applicationDirPath();
QObjectList objList = ui->widget->children();
foreach(QObject *obj, objList){
if (obj->objectName()=="label_icon"){
setQLabelIcon((QLabel*)obj, ":/icon/soft.png");
}
}
ui->listWidget_left_button_group->horizontalScrollBar()->setHidden(true);
addOneLeftButton(":/icon/kill.png",ZH("病毒查杀"),ZH("病毒查杀"),0);
addOneLeftButton(":/icon/protect.png",ZH("病毒防护"),ZH("病毒防护"),1);
addOneLeftButton(":/icon/u_disk.png",ZH("U盘保护"),ZH("U盘保护"),2);
ChildKillWnd *ckWnd = new ChildKillWnd(this);
connect(ckWnd,SIGNAL(sigSetFeatureCode(QJsonObject)),
this,SLOT(slotSetFeatureCode(QJsonObject)));
connect(ckWnd,SIGNAL(sigKillVirus(QJsonObject)),
this,SLOT(slotKillVirus(QJsonObject)));
connect(this,SIGNAL(sigDiskChanged()),
ckWnd,SLOT(slotDiskChanged()));
connect(this,SIGNAL(sigKillUDisk(QString)),
ckWnd,SLOT(slotKillUDisk(QString)));
ui->stackedWidget_child->addWidget(ckWnd);
ChildProtectWnd *cpWnd = new ChildProtectWnd(this);
ui->stackedWidget_child->addWidget(cpWnd);
ChildUDiskWnd *cudWnd = new ChildUDiskWnd(this);
ui->stackedWidget_child->addWidget(cudWnd);
PopVirusDefWnd *pvdWnd = new PopVirusDefWnd(this);
connect(pvdWnd,SIGNAL(sigFeatureCodeDefined(QJsonObject)),
this,SLOT(slotFeatureCodeDefined(QJsonObject)));
ui->stackedWidget_child->addWidget(pvdWnd);
PopKillVirusWnd *pkvWnd = new PopKillVirusWnd(this);
connect(pkvWnd, SIGNAL(sigQuitKillVirusWnd()),
this,SLOT(slotKillVirusWndQuit()),Qt::QueuedConnection);
connect(ckWnd,SIGNAL(sigKillVirus(QJsonObject)),
pkvWnd,SLOT(slotStartKillVirus(QJsonObject)));
ui->stackedWidget_child->addWidget(pkvWnd);
ui->listWidget_left_button_group->setCurrentRow(0);
connect(this,SIGNAL(sigNewUDiskInsert(QString)),
this,SLOT(slotNewUDiskInsert(QString)));
diskList_ = getDiskNameList();
}
/**
* @brief VirusScanWnd::addOneLeftButton
* @param iconPath
* @param text
* @param tooltip
* @param childIndex
* @return
*/
LeftButton *VirusScanWnd::addOneLeftButton(const QString &iconPath,
const QString &text,
const QString &tooltip,
int childIndex
)
{
QListWidgetItem *item = new QListWidgetItem;
item->setSizeHint(QSize(140,57));
ui->listWidget_left_button_group->addItem(item);
LeftButton *button = new LeftButton(this);
button->setIcon(iconPath);
button->setText(text);
button->setToolTip(tooltip);
button->setChildIndex(childIndex);
connect(button, SIGNAL(sigClicked(int)),
this,SLOT(slotLeftButtonClicked(int)));
ui->listWidget_left_button_group->setItemWidget(item, button);
return button;
}
/**
* @brief VirusScanWnd::nativeEvent
* @param eventType
* @param message
* @param result
* @return
*/
bool VirusScanWnd::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
MSG* msg = reinterpret_cast<MSG*>(message);
int msgType = msg->message;
if(msgType==WM_DEVICECHANGE)
{
DEV_BROADCAST_HDR *lpdb = (DEV_BROADCAST_HDR*)msg->lParam;
switch (msg->wParam) {
case DBT_DEVICEARRIVAL:
if(lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
DEV_BROADCAST_VOLUME *lpdbv = (DEV_BROADCAST_VOLUME*)lpdb;
if(lpdbv->dbcv_flags ==0)
{
QString uDisKName = getInsertUDiskName(diskList_);
qDebug() << __FUNCTION__ << "u disk insert " << uDisKName;
diskList_ = getDiskNameList();
emit sigDiskChanged();
emit sigNewUDiskInsert(uDisKName);
}
}
break;
case DBT_DEVICEREMOVECOMPLETE:
if(lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
DEV_BROADCAST_VOLUME *lpdbv = (DEV_BROADCAST_VOLUME*)lpdb;
if(lpdbv->dbcv_flags == 0)
{
qDebug() << __FUNCTION__ << "u disk remove " << getRemoveUDiskName(diskList_);
diskList_ = getDiskNameList();
emit sigDiskChanged();
}
}
break;
case DBT_DEVNODES_CHANGED:
{
qDebug() << "USB_change";
}
break;
}
}
return QWidget::nativeEvent(eventType, message, result);
}
/**
* @brief VirusScanWnd::slotLeftButtonClicked
* @param childIndex
*/
void VirusScanWnd::slotLeftButtonClicked(int childIndex)
{
ui->stackedWidget_child->setCurrentIndex(childIndex);
}
/**
* @brief VirusScanWnd::slotSetFeatureCode
* @param para
*/
void VirusScanWnd::slotSetFeatureCode(const QJsonObject ¶)
{
ui->stackedWidget_child->setCurrentIndex(WINDEX_POP_FEATURE_CODE_SET);
}
/**
* @brief VirusScanWnd::slotKillVirus
* @param para
*/
void VirusScanWnd::slotKillVirus(const QJsonObject ¶)
{
ui->stackedWidget_child->setCurrentIndex(WINDEX_POP_KILL_VIRUS);
}
/**
* @brief VirusScanWnd::slotKillVirusWndQuit
*/
void VirusScanWnd::slotKillVirusWndQuit()
{
ui->stackedWidget_child->setCurrentIndex(WINDEX_CHILD_VIRUS_KILL);
}
/**
* @brief VirusScanWnd::slotFeatureCodeDefined
* @param para
*/
void VirusScanWnd::slotFeatureCodeDefined(const QJsonObject ¶)
{
ui->stackedWidget_child->setCurrentIndex(WINDEX_CHILD_VIRUS_KILL);
}
/**
* @brief VirusScanWnd::slotNewUDiskInsert
* @param uDiskName
*/
void VirusScanWnd::slotNewUDiskInsert(const QString &uDiskName)
{
if (!gKillingVirus){
int ret = QMessageBox::question(this,
"please confirm",
QString("U disk %1 has inert.\nKill virus for %1").arg(uDiskName),
QMessageBox::Ok|QMessageBox::Cancel
);
if (ret==QMessageBox::Ok){
emit sigKillUDisk(uDiskName);
}
}
}
程序界面
程序下载
链接:https://pan.baidu.com/s/1xkDTRasnzTIPGMQFxi669g
提取码:1111