feat(example): add RemoteTerm example target and Qt6 fixes#595
feat(example): add RemoteTerm example target and Qt6 fixes#595yangwei-x wants to merge 1 commit intolxqt:masterfrom
Conversation
yangwei-x
commented
Sep 15, 2025
- Add optional RemoteTerm example (BUILD_EXAMPLE_REMOTETERM) with CMake target 'remoteterm'
- Use QStringLiteral for usage message in RemoteTerm main.cpp for Qt6 compatibility.
Add optional RemoteTerm example (BUILD_EXAMPLE_REMOTETERM) with CMake target 'remoteterm' Use QStringLiteral for usage message in RemoteTerm main.cpp for Qt6 compatibility.
|
@yan12125 |
yan12125
left a comment
There was a problem hiding this comment.
Some thoughts after a quick glance. Didn't test them yet
| Examples using QTermWidget | ||
| ========================== | ||
|
|
||
| This directory contains minimal examples showing how to embed and use `QTermWidget` in both C++ and Python (PyQt/PySide) applications. |
There was a problem hiding this comment.
Currently there is only PyQt binding, no official one for PySide yet.
| -------- | ||
| * `cpp/main.cpp` – Basic single–terminal C++ example with menu actions (Find / Copy / Paste / About Qt) and runtime selection of color schemes and key bindings via command‑line arguments. | ||
| * `cpp/RemoteTerm/` – A simple remote client example that connects to a TCP server exposing a pseudo terminal. Local keystrokes are sent to the remote host; data received over the socket is written into the local PTY backing the widget. | ||
| * `pyqt/` – Python examples (PyQt/PySide) demonstrating how to instantiate and configure the terminal widget from Python. See the files inside for details. |
| mkdir -p build | ||
| cd build | ||
| cmake -DBUILD_EXAMPLE=ON -DBUILD_EXAMPLE_REMOTETERM=ON .. | ||
| cmake --build . -j |
There was a problem hiding this comment.
Personally I'm not a fan of -j, which often makes the system hang, especially on not-so-powerful machines.
|
|
||
| Python Examples | ||
| --------------- | ||
| Install the Python bindings (PyQt6 recommended for Qt6 builds) and run the scripts directly, for example: |
There was a problem hiding this comment.
Minor: PyQt5 is no longer supported. Only PyQt6 is supported, so it is not only recommended, but also needed for the Python example.
|
Running Apparently the signal is renamed. Here is a quick fix: diff --git a/examples/cpp/RemoteTerm/remoteterm.cpp b/examples/cpp/RemoteTerm/remoteterm.cpp
index 551ac25..b48be65 100644
--- a/examples/cpp/RemoteTerm/remoteterm.cpp
+++ b/examples/cpp/RemoteTerm/remoteterm.cpp
@@ -18,7 +18,9 @@ RemoteTerm::RemoteTerm(const QString &ipaddr, quint16 port, QWidget *parent)
QByteArray data = socket->readAll();
write(this->getPtySlaveFd(), data.data(), data.size());
});
- connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(atError()));
+ connect(socket, &QTcpSocket::errorOccurred, [this](QAbstractSocket::SocketError){
+ atError();
+ });
// Here we start an empty pty.
this->startTerminalTeletype();After this, I got "Connection refused" for a random IP and port as expected. It would be great to have an example for the server to actually test the functionality of this program. |