/dev/pts/ hinzugefügt

This commit is contained in:
2026-08-11 14:16:26 +02:00
parent 72a2b7edd0
commit 1422efdc2f
9 changed files with 963 additions and 912 deletions

View File

@@ -4,6 +4,8 @@
#include <QVBoxLayout>
#include <QFileDialog>
#include <QLabel>
#include <QDir>
#include <algorithm>
ConnectDialog::ConnectDialog(QWidget *parent)
: QDialog(parent)
@@ -91,10 +93,47 @@ void ConnectDialog::refreshPorts()
m_portCombo->addItem(
QStringLiteral("%1 — %2").arg(info.portName(), info.description()),
info.portName());
// QSerialPortInfo::availablePorts() relies on udev/sysfs and does not
// enumerate pseudo-terminals, so PTY slaves (e.g. the ones created by
// `qemu -serial pty`) never show up above. Scan /dev/pts/ ourselves and
// list the numeric slave nodes as additional selectable "ports". Store
// the full path (e.g. "/dev/pts/4") as the item data so it is passed
// straight through to QSerialPort::setPortName(), which accepts either
// a bare name or a full system location. Baud/parity/etc. settings are
// simply no-ops on a PTY, which is fine for this use case.
addPtyPorts();
if (m_portCombo->count() == 0)
m_portCombo->addItem(tr("(no ports found)"), QString());
}
void ConnectDialog::addPtyPorts()
{
QDir ptsDir("/dev/pts");
if (!ptsDir.exists())
return;
// Entries are purely numeric device nodes (the "ptmx" master control
// device is excluded on purpose - it isn't a connectable endpoint).
QStringList nodes = ptsDir.entryList(QDir::System | QDir::NoDotAndDotDot);
QList<int> numbers;
for (const QString &node : std::as_const(nodes)) {
bool ok = false;
const int n = node.toInt(&ok);
if (ok)
numbers << n;
}
std::sort(numbers.begin(), numbers.end());
for (int n : std::as_const(numbers)) {
const QString path = QStringLiteral("/dev/pts/%1").arg(n);
m_portCombo->addItem(
QStringLiteral("%1 — pseudo-terminal (e.g. qemu -serial pty)").arg(path),
path);
}
}
void ConnectDialog::browseLogFile()
{
const QString path = QFileDialog::getSaveFileName(