我将部署QT创建者项目。但我发现部署.exe的某些功能缺失了。但是,它最初在QT创建者中工作。我不知道如何解决当前的问题,比如使用什么工具来帮助。缺少的功能是程序不显示有关视频文件的缩略图,我已将相关图像分配给该视频文件。
filemodel.h
#ifndef FILEMODEL_H
#define FILEMODEL_H
#include <QAbstractListModel>
#include <QDirIterator>
#include <QUrl>
#include <QMetaType>
#include <QFuture>
#include <QtConcurrent/QtConcurrent>
#include <iostream>
#include <QImage>
#include <iostream>
#include <fstream>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
struct File
{
Q_GADGET
Q_PROPERTY(QString name MEMBER name)
Q_PROPERTY(QUrl url MEMBER url)
Q_PROPERTY(QImage iconImg MEMBER iconImg)
Q_PROPERTY(QUrl urlicon MEMBER urlicon)
public:
QString name;
QUrl url;
QImage iconImg;
QUrl urlicon;
File(const QString& name=""){
//cout<<name.toStdString();
this->name = QFileInfo(name).fileName();
this->url = QUrl::fromLocalFile(name);
int i = name.toStdString().find(".mp4");
if(i<0)
{
this->urlicon = QUrl::fromLocalFile(name);
}
else{
string temp = QFileInfo(name).fileName().toStdString();
int j = temp.find(".mp4");
//string str = "C:\\Video\\"+ temp.replace(j,4,".jpg");
string str = "C:\\Video\\"+ temp.replace(j,4,".jpg");
this->urlicon = QUrl::fromLocalFile(QString::fromStdString(str));
}
}
};
Q_DECLARE_METATYPE(File)
class FileModel : public QAbstractListModel
{
enum dashBoardRoles {
NameRole=Qt::UserRole+1,
URLRole,
ICONRole,
URLICONRole
};
Q_OBJECT
Q_PROPERTY(QString folder READ folder WRITE setFolder NOTIFY folderChanged)
Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged)
public:
FileModel(QObject *parent=Q_NULLPTR):QAbstractListModel(parent){
}
Q_INVOKABLE QVariant get(int index){
return QVariant::fromValue(m_all_dirs[index]);
}
int rowCount(const QModelIndex &parent=QModelIndex()) const{
Q_UNUSED(parent)
return m_all_dirs.count();
}
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const{
if(index.row()<0 && index.row()>= rowCount())
return QVariant();
File file = m_all_dirs[index.row()];
if(role == NameRole)
return file.name;
else if(role == URLRole)
return file.url;
else if(role == ICONRole)
return file.iconImg;
else if(role == URLICONRole)
return file.urlicon;
return QVariant();
}
QHash<int, QByteArray> roleNames() const {
QHash <int,QByteArray> roles;
roles [NameRole]="fileName";
roles [URLRole]="url";
roles [ICONRole]="icon";
roles [URLICONRole]="urlicon";
return roles;
}
QString folder() const{
return mFolder;
}
void setFolder(const QString &folder)
{
if(mFolder == folder)
return;
mFolder = folder;
emit folderChanged();
findFiles();
}
QStringList nameFilters() const{
return mNameFilters;
}
void setNameFilters(const QStringList &nameFilters){
if(mNameFilters == nameFilters)
return;
mNameFilters = nameFilters;
emit nameFiltersChanged();
findFiles();
}
signals:
void folderChanged();
void nameFiltersChanged();
private:
void findFiles(){
beginResetModel();
m_all_dirs.clear();
if(QDir(mFolder).exists()){
QFuture<QStringList> future = QtConcurrent::run([=]() {
QStringList files;
QDirIterator it(mFolder, mNameFilters, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()){
files<<it.next();
}
ofstream myfile;
myfile.open (mFolder.toStdString()+"\\example.xml");
myfile <<"<files>"<<"\n";
for (int i = 0; i < files.size(); ++i)
myfile << "<"+ std::to_string(i) + ">"<< files.at(i).toStdString()<< "</"+ std::to_string(i) + ">" <<"\n";
//
myfile <<"</files>"<<"\n";
myfile.close();
for (int i = 0; i < files.size(); ++i){
int j = files.at(i).toStdString().find(".mp4");
if(j>0)
{
VideoCapture cap(files.at(i).toStdString());
Mat frame;
cap >> frame;
string str = QFileInfo(files.at(i)).fileName().toStdString();
int k = str.find(".mp4");
str = "C:\\Video\\"+ str.replace(k,4,".jpg");
imwrite(str,frame);
}
}
return files;
});
QStringList fullNames = future.result();
for(const QString& fullName: fullNames){
File file{fullName};
m_all_dirs << file;
}
//return 0;
}
endResetModel();
}
QString mFolder;
QList<File> m_all_dirs;
QStringList mNameFilters;
};
#endif // FILEMODEL_H
的main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "filemodel.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
qmlRegisterType<FileModel>("com.contentplayermod.filemodel", 1,0, "FileModel");
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
main.qml
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtMultimedia 5.8
import QtQuick.Layouts 1.3
import com.contentplayermod.filemodel 1.0
import QtQuick.Window 2.2
ApplicationWindow {
id:main_win
visible: true
width: 640
height: 480
title: qsTr("Tabs")
property int idx: 0
property bool isActive: true
Component.onCompleted: {
playTimer.start()
subWindow.show();
subWindow.requestActivate();
main_win.hide();
playMusic(grid_main.currentIndex)
}
GridView {
id:grid_main
anchors.fill: parent
cellWidth: 100; cellHeight: 100
focus: true
currentIndex: 0
model: FileModel{
id: myModel
folder: "c:\\test2"//"/mnt/sdcard/app_pictureFrameImage"//
nameFilters: ["*.jpg" ,"*.mp4"] //"*.mp4",
}
highlight: Rectangle { width: 80; height: 80; color: "lightsteelblue" }
delegate: Item {
width: 100; height: 100
Image {
id: myIcon
width: 30
height: 30
y: 20; anchors.horizontalCenter: parent.horizontalCenter
source: urlicon
}
Text {
anchors { top: myIcon.bottom; horizontalCenter: parent.horizontalCenter }
text: fileName
}
MouseArea {
anchors.fill: parent
onClicked: {
parent.GridView.view.currentIndex = index
}
}
}
Keys.onReturnPressed:{
playTimer.start()
subWindow.show();
subWindow.requestActivate();
playMusic(grid_main.currentIndex)
//subWindow.forceActiveFocus();
//event.accepted = true;
grid_main.focus = false;
}
/*
Keys.onPressed: {
if (event.key == 16777220) {//enter
playTimer.start()
subWindow.show();
subWindow.requestActivate();
playMusic(grid_main.currentIndex)
//subWindow.forceActiveFocus();
event.accepted = true;
grid_main.focus = false;
//main_win.hide();
}
}*/
}
Window {
id: subWindow
visible: true
width: 640
height: 480
MediaPlayer {
id: player
}
VideoOutput {
id: video
anchors.fill: parent
source: player
}
Item {
focus: true
Keys.onReturnPressed:{
subWindow.close()
grid_main.forceActiveFocus();
main_win.show();
}
}
}
function playMusic(index){
idx = index
//player.stop()
player.source = myModel.get(index).url
player.play()
}
Timer {
id: playTimer
interval: 2000
repeat: true
running: true
onTriggered: {
var source_name = player.source;
if(source_name.toString().indexOf(".jpg")>0 || source_name.toString().indexOf(".bmp")>0 || source_name.toString().indexOf(".png")>0){ //processing .jpg
if (idx + 1 < grid_main.count){
playMusic(idx + 1);
}else{
idx = 0;
playMusic(idx);
}
}
else if(source_name.toString().indexOf(".mp4")>0){ //processing .mp4
if (player.status == MediaPlayer.EndOfMedia){
if (idx + 1 < grid_main.count){
playMusic(idx + 1);
}else{
idx = 0;
playMusic(idx);
}
}
}
}
}
}