QTCPSocket with Qt 5.11.1 and Qt 5.6.1

  • Hello,

    I have a weird problem and I don't know how to solve it.

    I am trying to connect to a server with a QTCPSocket, like it is shown in the sample code below:

    MyClass::MyClass(QObject* parent)
      : QObject(parent)
      , socket(new QTCPSocket(this))
      connect(socket, &QTCPSocket::connected, this, &MyClass::connected);
      connect(socket, &QTCPSocket::disconnected, this, &MyClass::disconnected);
      connect(socket, &QTcpSocket::bytesWritten, this, &MyClass::getBytesWritten);
      connect(socket, &QTcpSocket::readyRead, this, &MyClass::readReady);
      QHostAddress address;
      socket->connectToHost(address, port);
              qDebug() << "Socket State: " << socket->state();
              qDebug() << "Error: " << socket->errorString();
    MyClass::send(const char* msg, qint64 bytes)
        socket->write(msg, bytes);
        if (!socket->waitForBytesWritten())
            qDebug() << "Socket State: " << socket->state();
            qDebug() << "Bytes could not be written!";
     // some random stuff which needs the transmitted data, I use socket->read(...)
      qDebug() << "alive!";
      qDebug() << "died!";
      qDebug() << "readReady";
    MyClass::getBytesWritten(qint64 bytes)
      qDebug() << "Wrote: " << bytes;

    If I use Qt 5.6.1 everything works as expected and I can successfully connect to the server. But if I compile and link against Qt 5.11.1 or Qt 5.10 it doesn't work. By observing the socket state and checking the error messages, there is no error shown and the connected signal is received. If I am trying to send some data, the socket changes its state to Unconnected and an error is shown, which states that the remote site quit the connection.


    When I check the TCP connection build-up with Wireshark, only with QT 5.6.1 I can see the TCP Sync and Ack. There is no build-up with Qt 5.10 and 5.11.1.

    Btw. I use Ubuntu 16.04 and there is no firewall blocking the connection.

    Can someone help me please?

  • @silau My guess here is you are mixing Qt versions. You think your application is using a particular Qt version for everything but it is finding another version in your path and using that.

    This is very common in linux because so many linux apps use Qt. So you usually have your system Qt and the one you are developing with. Those tend to get crossed a lot causing issues like this.

    Try running ldd <yourexe> and see what Qt libs it is outputting. You may find ones in there you didn't expect.

    The solution (or test to confirm) is to make sure you isolate your application and then run it. Do a full deployment build including all the support Qt libs and run that to see if the problem persists. Another thing I like to do to make sure I have truly isolated my application is to change permissions on my Qt to by non-usable by my user. Then I try running the app and if it executes then I know I have it deployed/isolated properly. Then I set my permissions back on my system and development Qt versions.

  • @ambershark Thank you for your help.

    	linux-vdso.so.1 =>  (0x00007ffed9701000)
    	libQt5Widgets.so.5 => /opt/Qt5.11.1/5.11.1/gcc_64/lib/libQt5Widgets.so.5 (0x00007f14126e6000)
    	libQt5Gui.so.5 => /opt/Qt5.11.1/5.11.1/gcc_64/lib/libQt5Gui.so.5 (0x00007f1411eea000)
    	libQt5Network.so.5 => /opt/Qt5.11.1/5.11.1/gcc_64/lib/libQt5Network.so.5 (0x00007f1411b55000)
    	libQt5Core.so.5 => /opt/Qt5.11.1/5.11.1/gcc_64/lib/libQt5Core.so.5 (0x00007f14113fb000)
    	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f141106f000)
    	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f1410e57000)
    	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1410a8d000)
    	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1410870000)
    	libGL.so.1 => /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 (0x00007f14105fd000)
    	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f14102f4000)
    	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f14100da000)
    	libicui18n.so.56 => /opt/Qt5.11.1/5.11.1/gcc_64/lib/libicui18n.so.56 (0x00007f140fc41000)
    	libicuuc.so.56 => /opt/Qt5.11.1/5.11.1/gcc_64/lib/libicuuc.so.56 (0x00007f140f889000)
    	libicudata.so.56 => /opt/Qt5.11.1/5.11.1/gcc_64/lib/libicudata.so.56 (0x00007f140dea6000)
    	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f140dca2000)
    	libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f140daa0000)
    	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f140d78f000)
    	/lib64/ld-linux-x86-64.so.2 (0x00007f1412f2a000)
    	libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f140d566000)
    	libxcb-dri3.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri3.so.0 (0x00007f140d363000)
    	libxcb-present.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-present.so.0 (0x00007f140d160000)
    	libxcb-sync.so.1 => /usr/lib/x86_64-linux-gnu/libxcb-sync.so.1 (0x00007f140cf59000)
    	libxshmfence.so.1 => /usr/lib/x86_64-linux-gnu/libxshmfence.so.1 (0x00007f140cd56000)
    	libglapi.so.0 => /usr/lib/x86_64-linux-gnu/libglapi.so.0 (0x00007f140cb26000)
    	libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f140c914000)
    	libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007f140c711000)
    	libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f140c50b000)
    	libX11-xcb.so.1 => /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007f140c309000)
    	libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f140bfcf000)
    	libxcb-glx.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0 (0x00007f140bdb6000)
    	libxcb-dri2.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri2.so.0 (0x00007f140bbb1000)
    	libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f140b98f000)
    	libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007f140b789000)
    	libdrm.so.2 => /usr/lib/x86_64-linux-gnu/libdrm.so.2 (0x00007f140b578000)
    	libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f140b308000)
    	libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f140b104000)
    	libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f140aefe000)

    These are the dynamically linked libraries after I isolated my executable. The essential Qt libraries are loaded from the correct path. Especially libQt5Network is loaded from my dev Qt installation. Is there any lib left that could cause my problem?

  • @silau It looks good but ldd doesn't always report exactly what is actually happening when you run your exe. It's a good start though. If you really wanted to trace it further you would have to ldd on each of those libs to see what they link. One of them could be using the 5.6 or whatever other version you may have. That being said I find that to be a bit unlikely though.

    When I get a little bit of time later today I will run your code using Arch linux and 5.11 and see what happens. That will help determine if maybe it's a bug in Qt (which I highly doubt for something that big).

    If it works for me the next steps for you would be to run it in the debugger and step through the working 5.6 one during socket connections and then the broken 5.11 one and see what is different.

    Another option is take it down to the simplest form and just use the chat example or something from Qt and see if it works with 5.11 and then try to see what is different.

    I'll let you know what I find out on my linux/Qt 5.11 in a bit.

    Edit: Didn't get a chance today, was really busy. I will run a quick test tomorrow some time though.