<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Is QTcpSocket example working]]></title><description><![CDATA[<p dir="auto">I have made client-server simulator in C. They are connected with tcp and it works. I want to build HMI with Qt and I used chapter 15 Tripplanner-Tripserver as an example but I can not make it run even locally. Can somebody confirm the example is correct or what shall be corrected.</p>
<p dir="auto">You will find examples in:<br />
[C++ GUI Programming with Qt4, 2nd Edition] <a href="http://www.informit.com/store/c-plus-plus-gui-programming-with-qt4-9780132354165" target="_blank" rel="noopener noreferrer nofollow ugc">http://www.informit.com/store/c-plus-plus-gui-programming-with-qt4-9780132354165</a></p>
<p dir="auto">-&gt;[Download]</p>
<p dir="auto">I am running 64bit Ubuntu.</p>
]]></description><link>https://forum.qt.io/topic/71962/is-qtcpsocket-example-working</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 11:29:53 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/71962.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 05 Oct 2016 03:57:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is QTcpSocket example working on Thu, 06 Oct 2016 04:25:19 GMT]]></title><description><![CDATA[<p dir="auto">@Wieland +1 for this. I remembered to check firewall.</p>
]]></description><link>https://forum.qt.io/post/352208</link><guid isPermaLink="true">https://forum.qt.io/post/352208</guid><dc:creator><![CDATA[jalomann]]></dc:creator><pubDate>Thu, 06 Oct 2016 04:25:19 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 20:27:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a><br />
<img src="https://assets.pinshape.com/uploads/image/file/20126/cookie-monster-3d-printing-20126.jpg" alt="" class=" img-fluid img-markdown" /><br />
munch, munch, mnm ...</p>
]]></description><link>https://forum.qt.io/post/352166</link><guid isPermaLink="true">https://forum.qt.io/post/352166</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Wed, 05 Oct 2016 20:27:45 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 20:26:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kshegunov">@<bdi>kshegunov</bdi></a><br />
<img src="https://cdn.meme.am/instances/40089637.jpg" alt="Give that man a cookie!" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/352164</link><guid isPermaLink="true">https://forum.qt.io/post/352164</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Wed, 05 Oct 2016 20:26:10 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 20:22:35 GMT]]></title><description><![CDATA[<p dir="auto">Forgot to add a minor detail to <a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a>'s answer. If you're running a 64 bit compiler, this function isn't an override but an overload so it will never be called from the base class:</p>
<pre><code>void TripServer::incomingConnection(int socketId)
</code></pre>
<p dir="auto"><code>qintptr</code> is different from <code>int</code>. <a href="http://doc.qt.io/qt-5/qtcpserver.html#incomingConnection" target="_blank" rel="noopener noreferrer nofollow ugc">Here's the documentiation on <code>incommingConnection()</code>.</a></p>
]]></description><link>https://forum.qt.io/post/352162</link><guid isPermaLink="true">https://forum.qt.io/post/352162</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Wed, 05 Oct 2016 20:22:35 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 19:49:48 GMT]]></title><description><![CDATA[<p dir="auto">Also, unrelated to Qt, depending on the paranoia level of your system's admin you might need to ask for adjusting the Mandatory Access Control / firewall settings.</p>
]]></description><link>https://forum.qt.io/post/352147</link><guid isPermaLink="true">https://forum.qt.io/post/352147</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 05 Oct 2016 19:49:48 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 19:38:57 GMT]]></title><description><![CDATA[<p dir="auto">TL;DR<br />
I applaud <a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a>'s dedication, though.</p>
]]></description><link>https://forum.qt.io/post/352146</link><guid isPermaLink="true">https://forum.qt.io/post/352146</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Wed, 05 Oct 2016 19:38:57 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 19:18:48 GMT]]></title><description><![CDATA[<p dir="auto">I downloaded compiled and executed the example and it works for me. You need to make some changes to make it work in Qt5 (mainly adding the widgets module), remove the std::srand useless part.</p>
<p dir="auto">You also need to adjust <code>incomingConnection</code> method adding the line <code>addPendingConnection(socket);</code> to comply with <a href="http://doc.qt.io/qt-5/qtcpserver.html#incomingConnection" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qtcpserver.html#incomingConnection</a></p>
<blockquote>
<p dir="auto">Note: If another socket is created in the reimplementation of this method, it needs to be added to the Pending Connections mechanism by calling addPendingConnection().</p>
</blockquote>
<p dir="auto">Make sure you start the server first and then the client</p>
]]></description><link>https://forum.qt.io/post/352143</link><guid isPermaLink="true">https://forum.qt.io/post/352143</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Wed, 05 Oct 2016 19:18:48 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 18:56:09 GMT]]></title><description><![CDATA[<p dir="auto">tripplanner.h</p>
<pre><code>#ifndef TRIPPLANNER_H
#define TRIPPLANNER_H

#include &lt;QDialog&gt;
#include &lt;QTcpSocket&gt;

#include "ui_tripplanner.h"

class QPushButton;

class TripPlanner : public QDialog, private Ui::TripPlanner
{
    Q_OBJECT

public:
    TripPlanner(QWidget *parent = 0);

private slots:
    void connectToServer();
    void sendRequest();
    void updateTableWidget();
    void stopSearch();
    void connectionClosedByServer();
    void error();

private:
    void closeConnection();

    QPushButton *searchButton;
    QPushButton *stopButton;
    QTcpSocket tcpSocket;
    quint16 nextBlockSize;
};

#endif

</code></pre>
<p dir="auto">tripplanner.cpp</p>
<pre><code>#include &lt;QtWidgets&gt;
#include &lt;QtNetwork&gt;

#include "tripplanner.h"

TripPlanner::TripPlanner(QWidget *parent)
    : QDialog(parent)
{
    setupUi(this);

    searchButton = buttonBox-&gt;addButton(tr("&amp;Search"),
                                        QDialogButtonBox::ActionRole);
    stopButton = buttonBox-&gt;addButton(tr("S&amp;top"),
                                      QDialogButtonBox::ActionRole);
    stopButton-&gt;setEnabled(false);
    buttonBox-&gt;button(QDialogButtonBox::Close)-&gt;setText(tr("&amp;Quit"));

    QDateTime dateTime = QDateTime::currentDateTime();
    dateEdit-&gt;setDate(dateTime.date());
    timeEdit-&gt;setTime(QTime(dateTime.time().hour(), 0));

    progressBar-&gt;hide();
    progressBar-&gt;setSizePolicy(QSizePolicy::Preferred,
                               QSizePolicy::Ignored);

    tableWidget-&gt;verticalHeader()-&gt;hide();
    tableWidget-&gt;setEditTriggers(QAbstractItemView::NoEditTriggers);

    connect(searchButton, SIGNAL(clicked()),
            this, SLOT(connectToServer()));
    connect(stopButton, SIGNAL(clicked()), this, SLOT(stopSearch()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

    connect(&amp;tcpSocket, SIGNAL(connected()), this, SLOT(sendRequest()));
    connect(&amp;tcpSocket, SIGNAL(disconnected()),
            this, SLOT(connectionClosedByServer()));
    connect(&amp;tcpSocket, SIGNAL(readyRead()),
            this, SLOT(updateTableWidget()));
    connect(&amp;tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(error()));
}

void TripPlanner::connectToServer()
{
#if 1
    tcpSocket.connectToHost(QHostAddress::LocalHost, 6178);
#else
    tcpSocket.connectToHost("tripserver.zugbahn.de", 6178);
#endif

    tableWidget-&gt;setRowCount(0);
    searchButton-&gt;setEnabled(false);
    stopButton-&gt;setEnabled(true);
    statusLabel-&gt;setText(tr("Connecting to server..."));
    progressBar-&gt;show();

    nextBlockSize = 0;
}

void TripPlanner::sendRequest()
{
    QByteArray block;
    QDataStream out(&amp;block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_3);
    out &lt;&lt; quint16(0) &lt;&lt; quint8('S') &lt;&lt; fromComboBox-&gt;currentText()
        &lt;&lt; toComboBox-&gt;currentText() &lt;&lt; dateEdit-&gt;date()
        &lt;&lt; timeEdit-&gt;time();

    if (departureRadioButton-&gt;isChecked()) {
        out &lt;&lt; quint8('D');
    } else {
        out &lt;&lt; quint8('A');
    }
    out.device()-&gt;seek(0);
    out &lt;&lt; quint16(block.size() - sizeof(quint16));
    tcpSocket.write(block);

    statusLabel-&gt;setText(tr("Sending request..."));
}

void TripPlanner::updateTableWidget()
{
    QDataStream in(&amp;tcpSocket);
    in.setVersion(QDataStream::Qt_4_3);

    forever {
        int row = tableWidget-&gt;rowCount();

        if (nextBlockSize == 0) {
            if (tcpSocket.bytesAvailable() &lt; sizeof(quint16))
                break;
            in &gt;&gt; nextBlockSize;
        }

        if (nextBlockSize == 0xFFFF) {
            closeConnection();
            statusLabel-&gt;setText(tr("Found %1 trip(s)").arg(row));
            break;
        }

        if (tcpSocket.bytesAvailable() &lt; nextBlockSize)
            break;

        QDate date;
        QTime departureTime;
        QTime arrivalTime;
        quint16 duration;
        quint8 changes;
        QString trainType;

        in &gt;&gt; date &gt;&gt; departureTime &gt;&gt; duration &gt;&gt; changes &gt;&gt; trainType;
        arrivalTime = departureTime.addSecs(duration * 60);

        tableWidget-&gt;setRowCount(row + 1);

        QStringList fields;
        fields &lt;&lt; date.toString(Qt::LocalDate)
               &lt;&lt; departureTime.toString(tr("hh:mm"))
               &lt;&lt; arrivalTime.toString(tr("hh:mm"))
               &lt;&lt; tr("%1 hr %2 min").arg(duration / 60)
                                    .arg(duration % 60)
               &lt;&lt; QString::number(changes)
               &lt;&lt; trainType;
        for (int i = 0; i &lt; fields.count(); ++i)
            tableWidget-&gt;setItem(row, i,
                                 new QTableWidgetItem(fields[i]));
        nextBlockSize = 0;
    }
}

void TripPlanner::stopSearch()
{
    statusLabel-&gt;setText(tr("Search stopped"));
    closeConnection();
}

void TripPlanner::connectionClosedByServer()
{
    if (nextBlockSize != 0xFFFF)
        statusLabel-&gt;setText(tr("Error: Connection closed by server"));
    closeConnection();
}

void TripPlanner::error()
{
    statusLabel-&gt;setText(tcpSocket.errorString());
    closeConnection();
}

void TripPlanner::closeConnection()
{
    tcpSocket.close();
    searchButton-&gt;setEnabled(true);
    stopButton-&gt;setEnabled(false);
    progressBar-&gt;hide();
}

</code></pre>
<p dir="auto"><a href="http://tripplanner.pro" target="_blank" rel="noopener noreferrer nofollow ugc">tripplanner.pro</a></p>
<pre><code>TEMPLATE      = app
QT           += network widgets
HEADERS       = tripplanner.h
SOURCES       = main.cpp \
                tripplanner.cpp
FORMS         = tripplanner.ui

</code></pre>
<p dir="auto">main.cpp</p>
<pre><code>#include &lt;QApplication&gt;

#include "tripplanner.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    TripPlanner tripPlanner;
    tripPlanner.show();
    return app.exec();
}

</code></pre>
<p dir="auto">tripplanner.ui</p>
<pre><code>&lt;ui version="4.0" &gt;
 &lt;class&gt;TripPlanner&lt;/class&gt;
 &lt;widget class="QDialog" name="TripPlanner" &gt;
  &lt;property name="geometry" &gt;
   &lt;rect&gt;
    &lt;x&gt;0&lt;/x&gt;
    &lt;y&gt;0&lt;/y&gt;
    &lt;width&gt;382&lt;/width&gt;
    &lt;height&gt;369&lt;/height&gt;
   &lt;/rect&gt;
  &lt;/property&gt;
  &lt;property name="windowTitle" &gt;
   &lt;string&gt;Trip Planner&lt;/string&gt;
  &lt;/property&gt;
  &lt;layout class="QGridLayout" &gt;
   &lt;item row="0" column="0" &gt;
    &lt;widget class="QGroupBox" name="tripInfoGroupBox" &gt;
     &lt;property name="title" &gt;
      &lt;string&gt;Trip Information&lt;/string&gt;
     &lt;/property&gt;
     &lt;layout class="QGridLayout" &gt;
      &lt;item row="3" column="0" &gt;
       &lt;widget class="QLabel" name="timeLabel" &gt;
        &lt;property name="text" &gt;
         &lt;string&gt;Appro&amp;amp;ximate Time:&lt;/string&gt;
        &lt;/property&gt;
        &lt;property name="buddy" &gt;
         &lt;cstring&gt;timeEdit&lt;/cstring&gt;
        &lt;/property&gt;
       &lt;/widget&gt;
      &lt;/item&gt;
      &lt;item row="2" column="1" &gt;
       &lt;widget class="QDateTimeEdit" name="dateEdit" &gt;
        &lt;property name="displayFormat" &gt;
         &lt;string&gt;yyyy-MM-dd&lt;/string&gt;
        &lt;/property&gt;
       &lt;/widget&gt;
      &lt;/item&gt;
      &lt;item row="3" column="1" &gt;
       &lt;widget class="QDateTimeEdit" name="timeEdit" &gt;
        &lt;property name="displayFormat" &gt;
         &lt;string&gt;hh:mm:ss&lt;/string&gt;
        &lt;/property&gt;
       &lt;/widget&gt;
      &lt;/item&gt;
      &lt;item row="2" column="0" &gt;
       &lt;widget class="QLabel" name="dateLabel" &gt;
        &lt;property name="text" &gt;
         &lt;string&gt;&amp;amp;Date:&lt;/string&gt;
        &lt;/property&gt;
        &lt;property name="buddy" &gt;
         &lt;cstring&gt;dateEdit&lt;/cstring&gt;
        &lt;/property&gt;
       &lt;/widget&gt;
      &lt;/item&gt;
      &lt;item row="1" column="0" &gt;
       &lt;widget class="QLabel" name="toLabel" &gt;
        &lt;property name="text" &gt;
         &lt;string&gt;&amp;amp;To:&lt;/string&gt;
        &lt;/property&gt;
        &lt;property name="buddy" &gt;
         &lt;cstring&gt;toComboBox&lt;/cstring&gt;
        &lt;/property&gt;
       &lt;/widget&gt;
      &lt;/item&gt;
      &lt;item row="4" column="0" colspan="2" &gt;
       &lt;layout class="QHBoxLayout" &gt;
        &lt;item&gt;
         &lt;widget class="QRadioButton" name="departureRadioButton" &gt;
          &lt;property name="text" &gt;
           &lt;string&gt;D&amp;amp;eparture&lt;/string&gt;
          &lt;/property&gt;
          &lt;property name="shortcut" &gt;
           &lt;string&gt;Alt+E&lt;/string&gt;
          &lt;/property&gt;
          &lt;property name="checked" &gt;
           &lt;bool&gt;true&lt;/bool&gt;
          &lt;/property&gt;
         &lt;/widget&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;widget class="QRadioButton" name="arrivalRadioButton" &gt;
          &lt;property name="text" &gt;
           &lt;string&gt;&amp;amp;Arrival&lt;/string&gt;
          &lt;/property&gt;
          &lt;property name="shortcut" &gt;
           &lt;string&gt;Alt+A&lt;/string&gt;
          &lt;/property&gt;
         &lt;/widget&gt;
        &lt;/item&gt;
       &lt;/layout&gt;
      &lt;/item&gt;
      &lt;item row="0" column="1" &gt;
       &lt;widget class="QComboBox" name="fromComboBox" &gt;
        &lt;property name="currentIndex" &gt;
         &lt;number&gt;0&lt;/number&gt;
        &lt;/property&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Berlin&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Bonn&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Bremen&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Dresden&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Düsseldorf&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Dortmund&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Frankfurt am Main&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Hannover&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Hamburg&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;München&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Nürnberg&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Rostock&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Stuttgart&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
       &lt;/widget&gt;
      &lt;/item&gt;
      &lt;item row="1" column="1" &gt;
       &lt;widget class="QComboBox" name="toComboBox" &gt;
        &lt;property name="currentIndex" &gt;
         &lt;number&gt;0&lt;/number&gt;
        &lt;/property&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Berlin&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Bonn&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Bremen&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Dresden&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Düsseldorf&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Dortmund&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Frankfurt am Main&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Hannover&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Hamburg&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;München&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Nürnberg&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Rostock&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
        &lt;item&gt;
         &lt;property name="text" &gt;
          &lt;string&gt;Stuttgart&lt;/string&gt;
         &lt;/property&gt;
        &lt;/item&gt;
       &lt;/widget&gt;
      &lt;/item&gt;
      &lt;item row="0" column="0" &gt;
       &lt;widget class="QLabel" name="fromLabel" &gt;
        &lt;property name="text" &gt;
         &lt;string&gt;&amp;amp;From:&lt;/string&gt;
        &lt;/property&gt;
        &lt;property name="buddy" &gt;
         &lt;cstring&gt;fromComboBox&lt;/cstring&gt;
        &lt;/property&gt;
       &lt;/widget&gt;
      &lt;/item&gt;
     &lt;/layout&gt;
    &lt;/widget&gt;
   &lt;/item&gt;
   &lt;item rowspan="3" row="0" column="1" &gt;
    &lt;widget class="QDialogButtonBox" name="buttonBox" &gt;
     &lt;property name="orientation" &gt;
      &lt;enum&gt;Qt::Vertical&lt;/enum&gt;
     &lt;/property&gt;
     &lt;property name="standardButtons" &gt;
      &lt;set&gt;QDialogButtonBox::Close&lt;/set&gt;
     &lt;/property&gt;
    &lt;/widget&gt;
   &lt;/item&gt;
   &lt;item row="1" column="0" &gt;
    &lt;widget class="QTableWidget" name="tableWidget" &gt;
     &lt;property name="columnCount" &gt;
      &lt;number&gt;6&lt;/number&gt;
     &lt;/property&gt;
     &lt;column&gt;
      &lt;property name="text" &gt;
       &lt;string&gt;Date&lt;/string&gt;
      &lt;/property&gt;
     &lt;/column&gt;
     &lt;column&gt;
      &lt;property name="text" &gt;
       &lt;string&gt;Departure&lt;/string&gt;
      &lt;/property&gt;
     &lt;/column&gt;
     &lt;column&gt;
      &lt;property name="text" &gt;
       &lt;string&gt;Arrival&lt;/string&gt;
      &lt;/property&gt;
     &lt;/column&gt;
     &lt;column&gt;
      &lt;property name="text" &gt;
       &lt;string&gt;Duration&lt;/string&gt;
      &lt;/property&gt;
     &lt;/column&gt;
     &lt;column&gt;
      &lt;property name="text" &gt;
       &lt;string&gt;Changes&lt;/string&gt;
      &lt;/property&gt;
     &lt;/column&gt;
     &lt;column&gt;
      &lt;property name="text" &gt;
       &lt;string&gt;Train type&lt;/string&gt;
      &lt;/property&gt;
     &lt;/column&gt;
    &lt;/widget&gt;
   &lt;/item&gt;
   &lt;item row="2" column="0" &gt;
    &lt;layout class="QHBoxLayout" &gt;
     &lt;item&gt;
      &lt;widget class="QLabel" name="statusLabel" &gt;
       &lt;property name="sizePolicy" &gt;
        &lt;sizepolicy vsizetype="Preferred" hsizetype="Expanding" &gt;
         &lt;horstretch&gt;0&lt;/horstretch&gt;
         &lt;verstretch&gt;0&lt;/verstretch&gt;
        &lt;/sizepolicy&gt;
       &lt;/property&gt;
       &lt;property name="text" &gt;
        &lt;string&gt;Ready&lt;/string&gt;
       &lt;/property&gt;
      &lt;/widget&gt;
     &lt;/item&gt;
     &lt;item&gt;
      &lt;widget class="QProgressBar" name="progressBar" &gt;
       &lt;property name="minimum" &gt;
        &lt;number&gt;0&lt;/number&gt;
       &lt;/property&gt;
       &lt;property name="maximum" &gt;
        &lt;number&gt;100&lt;/number&gt;
       &lt;/property&gt;
       &lt;property name="orientation" &gt;
        &lt;enum&gt;Qt::Horizontal&lt;/enum&gt;
       &lt;/property&gt;
      &lt;/widget&gt;
     &lt;/item&gt;
    &lt;/layout&gt;
   &lt;/item&gt;
  &lt;/layout&gt;
 &lt;/widget&gt;
 &lt;resources/&gt;
 &lt;connections/&gt;
&lt;/ui&gt;

</code></pre>
]]></description><link>https://forum.qt.io/post/352139</link><guid isPermaLink="true">https://forum.qt.io/post/352139</guid><dc:creator><![CDATA[jalomann]]></dc:creator><pubDate>Wed, 05 Oct 2016 18:56:09 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 18:52:11 GMT]]></title><description><![CDATA[<p dir="auto"><a href="http://tripserver.pro" target="_blank" rel="noopener noreferrer nofollow ugc">tripserver.pro</a></p>
<pre><code>TEMPLATE      = app
QT           += network widgets
HEADERS       = clientsocket.h \
                tripserver.h
SOURCES       = clientsocket.cpp \
                main.cpp \
                tripserver.cpp

</code></pre>
<p dir="auto">tripserver.h</p>
<pre><code>#ifndef TRIPSERVER_H
#define TRIPSERVER_H

#include &lt;QTcpServer&gt;

class TripServer : public QTcpServer
{
    Q_OBJECT

public:
    TripServer(QObject *parent = 0);

private:
    void incomingConnection(int socketId);
};

#endif

</code></pre>
<p dir="auto">tripserver.cpp</p>
<pre><code>#include &lt;QtCore&gt;

#include "clientsocket.h"
#include "tripserver.h"

TripServer::TripServer(QObject *parent)
    : QTcpServer(parent)
{
}

void TripServer::incomingConnection(int socketId)
{
    ClientSocket *socket = new ClientSocket(this);
    socket-&gt;setSocketDescriptor(socketId);
}

</code></pre>
<p dir="auto">clientsocket.h</p>
<pre><code>#ifndef CLIENTSOCKET_H
#define CLIENTSOCKET_H

#include &lt;QTcpSocket&gt;

class QDate;
class QTime;

class ClientSocket : public QTcpSocket
{
    Q_OBJECT

public:
    ClientSocket(QObject *parent = 0);

private slots:
    void readClient();

private:
    void generateRandomTrip(const QString &amp;from, const QString &amp;to,
                            const QDate &amp;date, const QTime &amp;time);

    quint16 nextBlockSize;
};

#endif
</code></pre>
<p dir="auto">clientsocket.cpp</p>
<pre><code>#include &lt;QtNetwork&gt;

#include "clientsocket.h"

ClientSocket::ClientSocket(QObject *parent)
    : QTcpSocket(parent)
{
    connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));

    nextBlockSize = 0;
}

void ClientSocket::readClient()
{
    QDataStream in(this);
    in.setVersion(QDataStream::Qt_4_3);

    if (nextBlockSize == 0) {
        if (bytesAvailable() &lt; sizeof(quint16))
            return;
        in &gt;&gt; nextBlockSize;
    }

    if (bytesAvailable() &lt; nextBlockSize)
        return;

    quint8 requestType;
    QString from;
    QString to;
    QDate date;
    QTime time;
    quint8 flag;

    in &gt;&gt; requestType;
    if (requestType == 'S') {
        in &gt;&gt; from &gt;&gt; to &gt;&gt; date &gt;&gt; time &gt;&gt; flag;

        std::srand(from.length() * 3600 + to.length() * 60
                   + time.hour());
        int numTrips = std::rand() % 8;
        for (int i = 0; i &lt; numTrips; ++i)
            generateRandomTrip(from, to, date, time);

        QDataStream out(this);
        out &lt;&lt; quint16(0xFFFF);
    }

    close();
}

void ClientSocket::generateRandomTrip(const QString &amp; /* from */,
        const QString &amp; /* to */, const QDate &amp;date, const QTime &amp;time)
{
    QByteArray block;
    QDataStream out(&amp;block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_3);
    quint16 duration = std::rand() % 200;
    out &lt;&lt; quint16(0) &lt;&lt; date &lt;&lt; time &lt;&lt; duration &lt;&lt; quint8(1)
        &lt;&lt; QString("InterCity");
    out.device()-&gt;seek(0);
    out &lt;&lt; quint16(block.size() - sizeof(quint16));
    write(block);
}

</code></pre>
<p dir="auto">main.cpp</p>
<pre><code>#include &lt;QtWidgets&gt;
#include &lt;iostream&gt;

#include "tripserver.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    TripServer server;
    if (!server.listen(QHostAddress::Any, 6178)) {
        std::cerr &lt;&lt; "Failed to bind to port" &lt;&lt; std::endl;
        return 1;
    }

    QPushButton quitButton(QObject::tr("&amp;Quit"));
    quitButton.setWindowTitle(QObject::tr("Trip Server"));
    QObject::connect(&amp;quitButton, SIGNAL(clicked()),
                     &amp;app, SLOT(quit()));
    quitButton.show();
    return app.exec();
}</code></pre>
]]></description><link>https://forum.qt.io/post/352137</link><guid isPermaLink="true">https://forum.qt.io/post/352137</guid><dc:creator><![CDATA[jalomann]]></dc:creator><pubDate>Wed, 05 Oct 2016 18:52:11 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 17:40:17 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
We got what the problem is, but I repeat:<br />
Please post the relevant code!</p>
<p dir="auto">Also from your clip I gathered you don't use a debugger, install and use a debugger, that's what it was invented for - to track down programming errors.</p>
]]></description><link>https://forum.qt.io/post/352124</link><guid isPermaLink="true">https://forum.qt.io/post/352124</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Wed, 05 Oct 2016 17:40:17 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 17:29:50 GMT]]></title><description><![CDATA[<p dir="auto">This is what happens: <a href="http://jalomann.fi/tripserver.mp4" target="_blank" rel="noopener noreferrer nofollow ugc">http://jalomann.fi/tripserver.mp4</a></p>
<p dir="auto">It is a very good book to learn Qt. I thought somebody would have been interested.</p>
]]></description><link>https://forum.qt.io/post/352122</link><guid isPermaLink="true">https://forum.qt.io/post/352122</guid><dc:creator><![CDATA[jalomann]]></dc:creator><pubDate>Wed, 05 Oct 2016 17:29:50 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 16:21:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jalomann">@<bdi>jalomann</bdi></a> said in <a href="/post/351952">Is QTcpSocket example working</a>:</p>
<blockquote>
<p dir="auto">Does QTcpSocket work at all?</p>
</blockquote>
<p dir="auto">Yes, since I've started using Qt - about 10 years ago. My suspicion it was working long before that too ...</p>
<blockquote>
<p dir="auto">Did somebody use for something usefull so far?</p>
</blockquote>
<p dir="auto">Thousands upon thousands of people I'd assume.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jalomann">@<bdi>jalomann</bdi></a> said in <a href="/topic/71962/is-qtcpsocket-example-working/8">Is QTcpSocket example working</a>:</p>
<blockquote>
<p dir="auto">I didn't want to paste the whole code here because it is in nice package.</p>
</blockquote>
<p dir="auto">Paste only the relevant part - where the connection is supposed to be established, then we can ask for more information if it's needed.</p>
]]></description><link>https://forum.qt.io/post/352109</link><guid isPermaLink="true">https://forum.qt.io/post/352109</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Wed, 05 Oct 2016 16:21:40 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 07:28:12 GMT]]></title><description><![CDATA[<p dir="auto">The code is found in the tarball in the link. I didn't want to paste the whole code here because it is in nice package. It compiles but it doesn't make the connection. I have debugged so for far that the constructor gets called but no connection. The progress bar is shown but it hangs there.</p>
]]></description><link>https://forum.qt.io/post/351979</link><guid isPermaLink="true">https://forum.qt.io/post/351979</guid><dc:creator><![CDATA[jalomann]]></dc:creator><pubDate>Wed, 05 Oct 2016 07:28:12 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 06:36:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jalomann">@<bdi>jalomann</bdi></a> localhost should work just fine.<br />
What exactly is the issue?</p>
]]></description><link>https://forum.qt.io/post/351962</link><guid isPermaLink="true">https://forum.qt.io/post/351962</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 05 Oct 2016 06:36:34 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 06:22:08 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
For other samples, this worked very well for me<br />
<a href="http://www.bogotobogo.com/cplusplus/sockets_server_client_QT.php" target="_blank" rel="noopener noreferrer nofollow ugc">http://www.bogotobogo.com/cplusplus/sockets_server_client_QT.php</a></p>
]]></description><link>https://forum.qt.io/post/351959</link><guid isPermaLink="true">https://forum.qt.io/post/351959</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Wed, 05 Oct 2016 06:22:08 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 06:03:30 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">As <a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a>  said, can u provide the code, so the users in the forum can come to know.<br />
Regarding the above mentioned Topic.</p>
<p dir="auto">Thanks,</p>
]]></description><link>https://forum.qt.io/post/351956</link><guid isPermaLink="true">https://forum.qt.io/post/351956</guid><dc:creator><![CDATA[Pradeep Kumar]]></dc:creator><pubDate>Wed, 05 Oct 2016 06:03:30 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 05:53:32 GMT]]></title><description><![CDATA[<p dir="auto">Hai...<br />
no worry...<br />
QTcpSocket works fine...</p>
]]></description><link>https://forum.qt.io/post/351955</link><guid isPermaLink="true">https://forum.qt.io/post/351955</guid><dc:creator><![CDATA[Venkatesh V]]></dc:creator><pubDate>Wed, 05 Oct 2016 05:53:32 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 05:48:57 GMT]]></title><description><![CDATA[<p dir="auto">Ou. Server-Client usually used to communicate over network.<br />
In this example client is used to ask train timetable between<br />
German towns. Server is supposed to create a random trip and<br />
timetable and send it over tcp connection back to client which<br />
in turn shows it in widget. In this case the address is set<br />
as localhost, so it should run on single computer.</p>
<p dir="auto">I see a lot of questions on forum about QTcpSocket.<br />
So the question is: Does QTcpSocket work at all? Did somebody<br />
use for something usefull so far?</p>
]]></description><link>https://forum.qt.io/post/351952</link><guid isPermaLink="true">https://forum.qt.io/post/351952</guid><dc:creator><![CDATA[jalomann]]></dc:creator><pubDate>Wed, 05 Oct 2016 05:48:57 GMT</pubDate></item><item><title><![CDATA[Reply to Is QTcpSocket example working on Wed, 05 Oct 2016 04:22:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jalomann">@<bdi>jalomann</bdi></a> How is anybody supposed to know what should be corrected if you do not tell us what is not working?<br />
Does it build? If not what error messages do you get? If it builds what happens on runtime?</p>
]]></description><link>https://forum.qt.io/post/351941</link><guid isPermaLink="true">https://forum.qt.io/post/351941</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 05 Oct 2016 04:22:01 GMT</pubDate></item></channel></rss>