forked from zl0i/QtAutoTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindeployqt.cpp
111 lines (96 loc) · 2.49 KB
/
windeployqt.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "windeployqt.h"
Windeployqt::Windeployqt(QObject *parent) : QProcess(parent)
{
connect(this, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, QOverload<int>::of(&Windeployqt::slotFinished));
connect(this, &QProcess::readyRead, this, &Windeployqt::slotReadChanel);
}
void Windeployqt::slotReadChanel() {
setReadChannel(QProcess::StandardError);
QByteArray error = readAll();
if(!error.isEmpty())
emit newErrorData(error);
setReadChannel(QProcess::StandardOutput);
QByteArray output = readAll();
if(!output.isEmpty())
emit newOutputData(output);
}
void Windeployqt::setExeFile(QString path)
{
exeFile = path;
}
void Windeployqt::setDir(QString path)
{
dir = path;
}
void Windeployqt::setPlugindir(QString path)
{
plugindir = path;
}
void Windeployqt::setLibdir(QString path)
{
libdir = path;
}
void Windeployqt::setQmlimport(QString path)
{
qmlimport = path;
}
void Windeployqt::setQmldir(QString path)
{
qmldir = path;
}
void Windeployqt::setFlags(QString flags)
{
this->flags = flags;
}
void Windeployqt::setLibraries(QString libraries)
{
this->libraries = libraries;
}
void Windeployqt::deploy()
{
if(!QFile(exeFile).exists())
return;
QStringList arguments;
if(!dir.isEmpty()) {
arguments.append("--dir " + dir);
}
if(!plugindir.isEmpty()) {
arguments.append("--plugindir " + plugindir);
}
if(!libdir.isEmpty()) {
arguments.append("--libdir " + libdir);
}
if(!qmldir.isEmpty()) {
arguments.append("--qmldir " + qmldir);
}
if(!qmlimport.isEmpty()) {
arguments.append("--qmlimport " + qmlimport);
}
if(!exeFile.isEmpty()) {
arguments.append(exeFile);
}
if(flags.length() != 0) {
arguments.append(flags);
}
if(libraries.length() != 0) {
arguments.append(libraries);
}
QFile *file = Worker::prepareBatFile(true);
QString str = Worker::getInstance()->compilerPath() + "/bin/windeployqt " + arguments.join(" ");
file->write(str.toLocal8Bit());
file->close();
file->deleteLater();
start(file->fileName());
}
void Windeployqt::slotFinished(int code) {
if(code > 0) {
emit newErrorData(readAllStandardError());
} else {
if(!dir.isEmpty()) {
QString nameExeFile = exeFile.split("/").last();
QFile::copy(exeFile, dir+"/" + nameExeFile);
}
}
Worker::removeBatFile();
}