一.前言
距离上次完成的Linux下QT实时音频采集传输项目已经有一个月的时间。之后又在Linux上完成了许多大大小小的项目,多是与UI有关。
这次给实现的是Windows下的QT+Mysql+海康sdk的远程录像下载程序。
需要QT连上Mysql,数据库版本必须和QT对应,32位QT是连不上64位的Mysql滴。连接方法可以参考这个文章:QT5.5连接mysql5.6 或 本文setsql.cpp中 sql_init() 函数的内容。
另外还测试了用SqlServer连接,原理差不多,只修改了连接部分,程序运行良好。
二.程序流程
程序的流程思路很简单:先通过QT进入本地Mysql数据库,遍历一张表,找出未下载过的录像记录并读取对应的IP和时间Time,逐个添加到海康sdk中,下载该IP号录像机在这个时间Time的录像。下载完毕后更新数据库。
1.Mysql表参考 (表名:ear)
EAR_Ip:录像机IP号 EAR_Time:下载该时间的录像
EAR_Confirm:确认是否下载(已下载为1,未下载为0)
2.海康sdk录像下载流程(截自官方的设备网络SDK使用手册)
写的非常清楚,对应的sdk函数都在里面写好了,跟着调用就好。本篇是按时间查找下载。
3.程序流程
二.项目代码
1. pro文件
手头的海康Lib、.h文件、.dll文件需要链接到QT上,不知道如何添加的朋友可以参考这篇文章:QT 添加 lib库
QT+= sql 要加上
#-------------------------------------------------
#
# Project created by QtCreator 2018-07-30T16:12:52
#
#-------------------------------------------------
QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = DownloadVideo
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
dialog.cpp \
setsql.cpp \
HK_sdk.cpp
HEADERS += dialog.h \
setsql.h\
HK_sdk.h
FORMS += dialog.ui
INCLUDEPATH += $$PWD/include
LIBS += -L$$PWD/ -lGdiPlus
LIBS += -L$$PWD/ -lHCAlarm
LIBS += -L$$PWD/ -lHCCore
LIBS += -L$$PWD/ -lHCGeneralCfgMgr
LIBS += -L$$PWD/ -lHCPreview
LIBS += -L$$PWD/ -lPlayCtrl
LIBS += -L$$PWD/ -lHCNetSDK
2. .h文件
HK_SDK.h
/*********************************
* 本文件主要包含海康SDK中
* 下载模块的各种接口函数
* 以及对QSTring格式的时间处理函数
* Jingenfan@126.com 姓值钱的金三岁
* --------2018年7月30日-----------
*********************************/
#ifndef HK_SDK_H
#define HK_SDK_H
#include <QApplication>
#include <QApplication>
#include <QProcess>
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QTextCodec>
#include <QDebug>
#include <QString>
#include <iostream>
#include <stdio.h>
#include <QTimer>
#include <QWidget>
#include <QObject>
#include <QDateTime>
#include <windows.h>
#include "windows.h"
#include "HCNetSDK.h"
using namespace std;
//因为要用到QTimer,因此继承QObject
class HK_SDK:public QObject
{
Q_OBJECT
public:
explicit HK_SDK(QObject *parent=0);
~HK_SDK();
void HK_Login(QString ip); //登录设备
bool HK_DownLoadVideo(