Qt World Summit: Submit your Presentation

QTcpSocket/QMQTT - Strange Error Codes

  • I'm using Qt 5.9.1 on a Windows 10 machine and develop a program which can control shutters through MQTT-Messages for other Windows 10 machines.

    For the MQTT part I use a client which I found on GitHub (https://github.com/emqtt/qmqtt). The program works perfectly fine on my machine.

    The progam has one big problem: it does not run on every machine (statistically on 1/3 of all tested machines). I'm having some debug output on a console window, which gives me an error on the machines that don't work.

    There are only two ocurring errors:

    • QMQTT::SocketUnsupportedSocketOperationError (QAbstractSocket::UnsupportedSocketOperationError)
    • QMQTT::SocketAccessError (QAbstractSocket::SocketAccessError)

    In the program the error has the type QMQTT::ClientError, which is a "copy" of the QAbstractSocket::SocketError type. The errors already occur after I call the connectToHost() method of the QMQTT-Client.

    like this:

    QMQTT::Client client(QHostAddress(""), 1883);
    // set username etc.
    // connect error signal to a function to print errors

    What I already did:

    I followed the QMQTT::Client::connectToHost() slot in the source code and got to a point where the QTcpSocket::connectToHost() method is called. I added a console ouput before this call. If a machine, that does not work, runs this program it gets the output and right after that follows the error message.

    A further point tells me that the problem has to do something with the user directory.
    To dig even deeper, I figured out that the problem is connected to the NTUSER.DAT file inside the users home directory. If the file gets renamed and the user relogs into his account, he gets a brand new NTUSER.DAT file and my program runs with zero errors occuring. When he uses his old NTUSER.DAT again, the programs stops working. It also works when a new profile runs the program.

    I glimpsed into the QTcpSocket source code and was able to connect some Windows Errors to my ocurring Qt Errors. In the Microsoft Documentation I found the meaning for those Errors but they don't seem to fit in the picture

    I hope someone can help me with this problem. For now my best option seems to be to look forward for Qt 5.10 an the MQTT-Client that ships with it but thats to much time for just waiting.

    Thanks in advance !

  • NTUSER.DAT is the windows registry. it looks like you have a key set that shuts down your program. This does not sound like a Qt-related issue

  • @g.hirsch
    I'm not sure, but you can change port number 1883 to something else and check again. It's possible on some systems this port to be in use.
    By the way, first error means this:

    The requested socket operation is not supported by the local operating system (e.g., lack of IPv6 support).

  • I saw this old thread of mine and remembered, that the issue was solved. Just writing to explain how I solved it.

    The problem was in the proxy settings. People who had their proxy configuration to automatic could connect, everyone else could not.

    First solution was to set the configuration to automatic on every client. Which was cumbersome and seemed stupid, because the program does not need any proxy.
    A little later I found out, that there was a problem with the Qt Network Interface, it was a known bug and could be worked around by telling the program manually to not use any proxy:

    /* call before connecting to network. Easiest way is, just call somewhere at the beginning of the program */

  • I had the same problem. After installing winsdksetup.exe, I solved the problem.

  • This thread was helpful in resolving a customer issue recently.

    I was trying to use QTcpSocket::connectToHost(hostName, port) and was seeing the error signal with error type QAbstractSocket::UnsupportedSocketOperationError.

    Following the hints in this thread, I asked the customer to check their proxy settings. It was not set to Automatic, and setting it to Automatic resolved the connection problem.

    There are a couple of things I would like to understand/confirm:

    1. The comment of @g-hirsch above suggests it was (is?) a known bug. Does anyone know if and when this was fixed? We are currently on Qt 5.9.6 but hope we will be able to upgrade (probably to 5.15) next year.
    2. The fix suggested was to call QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy). I don't have a good understanding of what this does. Beyond working around this issue, are there any implications of calling this? Are there any situations where it might introduce new issues?

  • @Bob64 said in QTcpSocket/QMQTT - Strange Error Codes:

    I don't have a good understanding of what this does

    Have you checked the documentation of such method?

  • @Pablo-J-Rogina yes, and it doesn't say much more than what can be gleaned from the function signature. What is missing is any discussion of why one might want to call it (in normal circumstances that is, not to work around what apparently is a bug). Also, as I asked, whether calling it might have any adverse effects.