Nominate our 2022 Qt Champions!

SOLVED: QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState

  • I am getting the following error:

    QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState

    Basically, I instantiate QUdpSocket and it seems to connect fine because on my log it says "Listening on port". And then when I run nestat on ubuntu it shows that port in use.

    @Gateway::Gateway(QObject *parent, qint16 port, bool load_mirrors)
    m_socket(new QUdpSocket(this)),
    m_database(new Database(this)),
    m_notify(new Notify(this))

    connect(m_socket, SIGNAL(readyRead()),
    this, SLOT(readData()));

    if (m_socket->bind(m_port)) {
    Log::write(QString("Listening on port %1\n").arg(port), Log::LogAll);
    } else {
    Log::write(QString("Socket Bind Error: %1\n").arg(m_socket->errorString()), Log::LogAll);
    m_exit = true;

    void Gateway::readData()
    while (m_socket->hasPendingDatagrams()) {
    QByteArray data;
    m_socket->readDatagram(, data.size(),
    &m_clientAddr, &m_clientPort);
    Log::write(QString("Data from socket: %1\n").arg(GprsMsg::toAsciiString(data)));

    But it seems like that log "Data from socket: " in readData() is never reached. So I am not sure what the issue can be.

  • Lifetime Qt Champion


    Might be stupid question but… Are you sending anything to that port ?

  • It was because the vpn was down

  • Lifetime Qt Champion

    Glad you found out !

    Can you please also update the thread title prepending [solved] so other forum users may know a solution has been found :)

Log in to reply