使用QT的QML语言生成VLC-QT播放器

刚刚接触QT,发现它提供的QML可以像网页CSS一样制作界面,很方便。为了熟悉一下QML技术,参照VLC-QT的demo,使用其QML库编写一个简单的视频播放器。

工程很简单,直接贴代码

demo.pro

1
2
3
4
5
6
7
8
9
10
TEMPLATE = app

QT += qml quick
CONFIG += c++11

SOURCES += main.cpp

RESOURCES += qml.qrc

LIBS += -lVLCQtCore -lVLCQtQml

main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <QtCore/QCoreApplication>
#include <QtGui/QGuiApplication>
#include <QtQuick/QQuickView>

#include <VLCQtCore/Common.h>
#include <VLCQtQml/QmlVideoPlayer.h>

int main(int argc, char *argv[])
{
QCoreApplication::setApplicationName("VLC-Qt QML Player");
QCoreApplication::setAttribute(Qt::AA_X11InitThreads);

QGuiApplication app(argc, argv);
VlcCommon::setPluginPath(app.applicationDirPath() + "/plugins");
VlcQmlVideoPlayer::registerPlugin();

QQuickView quickView;
quickView.setSource(QUrl(QStringLiteral("qrc:/qml/video.qml")));
quickView.setResizeMode(QQuickView::SizeRootObjectToView);
quickView.show();

return app.exec();
}

qml.qrc

1
2
3
4
5
<RCC>
<qresource prefix="/qml">
<file>video.qml</file>
</qresource>
</RCC>

video.qml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import VLCQt 1.0
import QtQuick.Layouts 1.0

Rectangle {
width: 1020
height: 620
color: "yellow"

GridLayout{
id:vo
columns: 2
rows:2
anchors.fill: parent
Rectangle {
id:r1
color: "green"
Layout.fillWidth: true
Layout.fillHeight: true
VlcVideoPlayer {
id: vidwidget1
anchors.fill: parent
url: "rtsp://192.168.1.3:8554/xiao.mkv"
}
}

Rectangle {
id:r2
color: "green"
Layout.fillWidth: true
Layout.fillHeight: true
VlcVideoPlayer {
id: vidwidget2
anchors.fill: parent
url: "rtsp://192.168.1.3:8554/2.mkv"
}
}

Rectangle {
id:r3
color: "green"
Layout.fillWidth: true
Layout.fillHeight: true
VlcVideoPlayer {
id: vidwidget3
anchors.fill: parent
url: "rtsp://192.168.1.3:8554/3.mkv"
}
}

Rectangle {
id:r4
color: "green"
Layout.fillWidth: true
Layout.fillHeight: true
VlcVideoPlayer {
id: vidwidget4
anchors.fill: parent
url: "rtsp://192.168.1.3:8554/4.mkv"
}
}

}

}

效果

有个大问题,这样编译出来的程序,在QT run情况下能够正常运行。但是直接打开exe文件会提示QT5NetWork.dll找不到程序接入点,好奇怪呀,不知道哪里的原因。

虽然很不要脸,但是还请您多多打赏 ^_^