3、项目的整体UI架构

目录

  • 一、MYPlayer.pro详解
  • 二、Visual Stdio启动源代码
    • 1 - 生成vs项目文件
    • 2 - vs下项目的目录结构说明
    • 3 - MainApp.h启动类分析

一、MYPlayer.pro详解

MYPlayer.pro:记录了整个项目工程的设置,不建议随便修改

  • 项目模板:建立一个应用程序的makefile
# Project Type
TEMPLATE = app
  • QT引用模块
# Qt modules that are used by your project
QT += qml quick gui widgets multimedia opengl openglextensions
  • 项目编译选项与库
# Project configuration and compiler options
CONFIG += qt warn_on c++11 rtti stl thread exceptions
  • moc文件路径配置:moc 全称是 Meta-Object Compiler,也就是“元对象编译器”;编译之后就看到moc文件
    • Qt 不是使用的“标准的” C++ 语言,而是对其进行了一定程度的“扩展”。这里我们从Qt新增加的关键字就可以看出来:signals、slots 或者 emit。所以有人会觉得 Qt 的程序编译速度慢,这主要是因为在 Qt 将源代码交给标准 C++ 编译器,如 gcc 之前,需要事先将这些扩展的语法去除掉。完成这一操作的就是 moc
    • moc 全称是 Meta-Object Compiler,也就是“元对象编译器”。Qt 程序在交由标准编译器编译之前,先要使用 moc 分析 C++ 源文件。如果它发现在一个头文件中包含了宏 Q_OBJECT,则会生成另外一个 C++ 源文件。这个源文件中包含了 Q_OBJECT 宏的实现代码。这个新的文件名字将会是原文件名前面加上 moc_ 构成。这个新的文件同样将进入编译系统,最终被链接到二进制代码中去。因此我们可以知道,这个新的文件不是“替换”掉旧的文件,而是与原文件一起参与编译。另外,我们还可以看出一点,moc 的执行是在预处理器之前。因为预处理器执行之后,Q_OBJECT 宏就不存在了
# 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
    }
}
  • 指定项目目标可执行的文件名:其中不包含任何的扩展、前缀或版本号(默认的是当前的目录名)
# Name of the target file
TARGET = MYPlayer
  • 指定项目资源文件、code的编码
# 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
  • 项目使用的jml和js文件
# Source files which contains strings for i18n
lupdate_only {
    SOURCES += resource/ui/qml/*.qml \
              resource/ui/qml/*.js
}
  • 翻译文件:可以打开resource/ui/translation/MYPlayer_zh_CN.ts文件查看,支持中英文的翻译
# Translation file path
TRANSLATIONS += ./resource/ui/translation/MYPlayer_zh_CN.ts

3、项目的整体UI架构_第1张图片

  • 编译选项定义:QT_DEPRECATED_WARNINGS表示QT的某些功能被标记为过时的时候,编译器会发出警告
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
  • 项目源文件
# 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 Stdio启动源代码

1 - 生成vs项目文件

  • a.项目目录下新建GenerateVCProj.batqmake -tp vc MYPlayer.pro
    3、项目的整体UI架构_第2张图片
  • b.运行GenerateVCProj.bat生成vs项目文件:使用vs打开MYPlayer.vcxproj文件即可启动vs项目
    3、项目的整体UI架构_第3张图片

2 - vs下项目的目录结构说明

3、项目的整体UI架构_第4张图片

3 - MainApp.h启动类分析

  • class MainApp : public QApplication:MainApp继承QApplication类,主要是为了完成程序初始化的工作,而这部分初始化工作的目的是为了在项目中建立界面管理的机制

3、项目的整体UI架构_第5张图片

  • MainApp中加入了Q_OBJECT宏:这样之后我们的项目中就可以使用信号(signal)和槽(slot)机制
    3、项目的整体UI架构_第6张图片
  • MainApp的成员变量
    3、项目的整体UI架构_第7张图片
  • MainApp的成员方法
    3、项目的整体UI架构_第8张图片
  • 信号和槽
    3、项目的整体UI架构_第9张图片
  • QML属性-Q_PROPERTY:QML界面层的处理关联上逻辑层的复杂逻辑
    Q_PROPERTY(int demoNum READ demoNum WRITE setDemoNum NOTIFY demoNumChanged):demoNum变量读、写、更改都会在界面上触发事件
    Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged):同理语言的读、写、更改也会关联

3、项目的整体UI架构_第10张图片

你可能感兴趣的:(QT实战:视频播放器,ui,c++,qt)