forked from qt-creator/qt-creator
Docker: Tweak handling of DISPLAY
Passing the DISPLAY variable differently on Windows allows to even run a gui application on the docker image if there is an XServer (e.g. vcxsrv) running on the Windows host that can be used. Change-Id: I36f849c4efc6e53ef92fcea96b4b256fd92a01c6 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -68,7 +68,9 @@
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QHeaderView>
|
||||
#include <QHostAddress>
|
||||
#include <QLoggingCategory>
|
||||
#include <QNetworkInterface>
|
||||
#include <QPushButton>
|
||||
#include <QRandomGenerator>
|
||||
#include <QRegularExpression>
|
||||
@@ -772,6 +774,20 @@ void DockerDevicePrivate::stopCurrentContainer()
|
||||
proc.runBlocking();
|
||||
}
|
||||
|
||||
static QString getLocalIPv4Address()
|
||||
{
|
||||
const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
|
||||
for (auto &a : addresses) {
|
||||
if (a.isInSubnet(QHostAddress("192.168.0.0"), 16))
|
||||
return a.toString();
|
||||
if (a.isInSubnet(QHostAddress("10.0.0.0"), 8))
|
||||
return a.toString();
|
||||
if (a.isInSubnet(QHostAddress("172.16.0.0"), 12))
|
||||
return a.toString();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void DockerDevicePrivate::startContainer()
|
||||
{
|
||||
QString tempFileName;
|
||||
@@ -782,9 +798,11 @@ void DockerDevicePrivate::startContainer()
|
||||
tempFileName = temp.fileName();
|
||||
}
|
||||
|
||||
const QString display = HostOsInfo::isWindowsHost() ? QString(getLocalIPv4Address() + ":0.0")
|
||||
: QString(":0");
|
||||
CommandLine dockerRun{"docker", {"run", "-i", "--cidfile=" + tempFileName,
|
||||
"--rm",
|
||||
"-e", "DISPLAY=:0",
|
||||
"-e", QString("DISPLAY=%1").arg(display),
|
||||
"-e", "XAUTHORITY=/.Xauthority",
|
||||
"--net", "host"}};
|
||||
|
||||
|
Reference in New Issue
Block a user