0
点赞
收藏
分享

微信扫一扫

C++ QT结合FFmpeg实战开发视频播放器-08播放器项目的整体UI架构

乐百川 2022-08-15 阅读 37


作者:虚坏叔叔

早餐店不会开到晚上,想吃的人早就来了!😄

一、QT项目设置文件MyPlayer.Pro的讲解

​MyPlayer.Pro​​项目文件定义整个项目的设置。我们来看下这个文件的具体含义。

这个项目首先使用了​​QT​​​的模板​​app​​:

# Project Type
TEMPLATE = app

下面确定了​​QT​​要引用的模块,

# Qt modules that are used by your project
QT += qml quick gui widgets multimedia opengl openglextensions

工程编译选项需要定义​​QT​​​以及​​C++11​​​、​​STL​​等一系列标准,

# Project configuration and compiler options
CONFIG += qt warn_on c++11 rtti stl thread exceptions

设置​​moc​​​文件的路径:​​moc​​文件是由 系统中的QT开发环境根据头文件中的​​宏​​​来生成的。我们编译之后,就能看到​​moc​​文件。

# Directory where all intermediate objects and moc files should be placed
CONFIG(debug, debug|release) {
OBJECTS_DIR = ./tmp/debug
MOC_DIR = ./tmp/debug
} else {
OBJECTS_DIR = ./tmp/release
MOC_DIR = ./tmp/release
}

临时文件以及资源的配置文件

# Directory where all intermediate files from uic should be placed
CONFIG(debug, debug|release) {
UI_DIR = ./tmp/debug
} else {
UI_DIR = ./tmp/release
}

# Directory for Qt Resource Compiler output files
CONFIG(debug, debug|release) {
RCC_DIR = ./tmp/debug
} else {
RCC_DIR = ./tmp/release
}

指定​​Debug​​​和​​Release​​生成文件的目录。

# Specifies where to put the target file
CONFIG(debug, debug|release) {
contains(QMAKE_TARGET.arch, x86_64) {
DESTDIR = $$_PRO_FILE_/../../../bin/debug/x64
} else {
DESTDIR = $$_PRO_FILE_/../../../bin/debug/x86
}
} else {
contains(QMAKE_TARGET.arch, x86_64) {
DESTDIR = $$_PRO_FILE_/../../../bin/release/x64
} else {
DESTDIR = $$_PRO_FILE_/../../../bin/release/x86
}
}

工程的名称叫做​​MyPlayer​

# Name of the target file
TARGET = MYPlayer

定义了资源文件的名称以及编码方式

# Name of the resource collection files (qrc) for the target
RESOURCES += resource/MYPlayer.qrc
#RESOURCES += qml.qrc

# Codec configuration
CODECFORTR = UTF-8
CODECFORSRC = UTF-8

资源文件还包含了​​qml​​​和​​js​​文件

# Source files which contains strings for i18n
lupdate_only {
SOURCES += resource/ui/qml/*.qml \
resource/ui/qml/*.js
}

定义了翻译文件,支持中文翻译,帮助开发多语言的软件。

# Translation file path
TRANSLATIONS += ./resource/ui/translation/MYPlayer_zh_CN.ts

C++ QT结合FFmpeg实战开发视频播放器-08播放器项目的整体UI架构_app

这里是我们需要添加的源文件:

# Source files in the project
SOURCES += \
MYAudioPlay.cpp \
MYAudioThread.cpp \
MYDecode.cpp \
MYDecodeThread.cpp \
MYDemux.cpp \
MYDemuxThread.cpp \
MYResample.cpp \
MYVideoThread.cpp \
MYVideoOutput.cpp \
MYPlay.cpp \
main.cpp \
MainApp.cpp \
MYSubTitle.cpp \

以及头文件:

# Header files for the project
HEADERS += MainApp.h \
IVideoCall.h \
MYAudioPlay.h \
MYAudioThread.h \
MYDecode.h \
MYDecodeThread.h \
MYDemux.h \
MYDemuxThread.h \
MYResample.h \
MYVideoThread.h \
MYVideoOutput.h \
MYPlay.h \
MYSubTitle.h \

项目中使用到的头文件包含路径:

# Include path
INCLUDEPATH += ../../include

项目中需要使用到的库文件包含路径:

# Libaray path and libaray
CONFIG(debug, debug|release) {
contains(QMAKE_TARGET.arch, x86_64) {
LIBS += -L"$$PWD/../../lib/debug/x64/"
} else {
LIBS += -L"$$PWD/../../lib/debug/x86/"
}
# win32:LIBS += libqrencode.lib\
# libzint.lib
# unix:LIBS += -lqrencode\
# -lzint
} else {
contains(QMAKE_TARGET.arch, x86_64) {
LIBS += -L"$$PWD/../../lib/release/x64/"
} else {
LIBS += -L"$$PWD/../../lib/release/x86/"
}
# win32:LIBS += libqrencode.lib\
# libzint.lib
# unix:LIBS += -lqrencode\
# -lzint
}
win32:LIBS += avformat.lib\
avcodec.lib\
avutil.lib\
swresample.lib\
swscale.lib

​Win32​​​平台下还需要​​rc​​的资源文件:

# Windows platform
win32 {
RC_FILE = win32/MYPlayer.rc
HEADERS += win32/targetver.h \
win32/resource.h
OTHER_FILES += win32/MYPlayer.rc
}

其他平台我们并没有维护:

################################################################################
# Linux platform
linux {
}

################################################################################
# Mac OS X platform
macx {
}

我们保证是默认的就可以。

二 、在Visual Studio环境下程序启动源代码

双击​​GenerateVCProj.bat​​​文件,会自动生成​​MYPlayer.vcxproj​​:

C++ QT结合FFmpeg实战开发视频播放器-08播放器项目的整体UI架构_QT_02


C++ QT结合FFmpeg实战开发视频播放器-08播放器项目的整体UI架构_架构_03

查看​​MainApp.h​​​,为什么要继承​​QApplication​​​,因为我们希望在​​MainApp​​这个类中完成程序初始化的工作,这部分初始化的工作的目的是为了建立界面管理的机制。

C++ QT结合FFmpeg实战开发视频播放器-08播放器项目的整体UI架构_app_04

可以先看下这个类的成员变量

C++ QT结合FFmpeg实战开发视频播放器-08播放器项目的整体UI架构_QT_05

类的方法:

C++ QT结合FFmpeg实战开发视频播放器-08播放器项目的整体UI架构_架构_06

[

​Q_PROPERTY​​实现界面层和复杂的逻辑处理绑定

绑定了​​demoNum​​变量读、写、更改方法:

// For QML property(-ies)
// e.g.
Q_PROPERTY(int demoNum READ demoNum WRITE setDemoNum NOTIFY demoNumChanged)

// For QML property(-ies)
// e.g.
// demoNum
int demoNum() const;
void setDemoNum(int newValue);

QString language() const;
void setLanguage(QString newValue);

三、总结

  • 本文讲解了整体的项目配置和项目app启动类。



举报

相关推荐

Qt视频播放器

0 条评论