Results 1 to 4 of 4

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2019
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

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

    Im having trouble with my telnet connection by TCP where i need to enter the initials twice as the server needs this (not my server) but then when i have the initials entered once and are about to type them in the second time it seems like im getting thrown off
    this is the code when i push a button it needs to connect by TCP to a ip entered in the GUI
    IMPORTANT when i try and connect to the server with putty it works fine
    Qt Code:
    1. void MainWindow::on_reboot_clicked()
    2. {
    3. QString hostName = ui->hostName->text();
    4. int port = ui->Port->text().toInt();
    5.  
    6. socket = new QTcpSocket(this);
    7.  
    8. //connection
    9. socket->connectToHost(hostName, port, QIODevice::ReadWrite);
    10.  
    11. if(socket->waitForConnected(300)){//if succesfull connection run this
    12. qDebug() << "connected";
    13.  
    14. //sending initials first time
    15. socket->write("admin\r\n");
    16. socket->waitForReadyRead(10);
    17. qDebug() << "reading first" << socket->readAll();
    18. socket->waitForBytesWritten(10);
    19. //socket->waitForReadyRead(10);
    20. socket->write("Admin1\r\n");
    21. socket->waitForReadyRead(10);
    22. socket->waitForBytesWritten(10);
    23. //socket->waitForReadyRead(10);
    24. qDebug() << "reading second" << socket->readAll();
    25.  
    26. //sending initials second time
    27. socket->write("admin\r\n");
    28. socket->waitForReadyRead(10);
    29. socket->waitForBytesWritten(10);
    30. //socket->waitForReadyRead(10);
    31. qDebug() << "reading third" << socket->readAll();
    32. socket->write("Admin1\r\n");
    33. socket->waitForReadyRead(10);
    34. socket->waitForBytesWritten(10);
    35. //socket->waitForReadyRead(10);
    36. qDebug() << "reading fourth" << socket->readAll();
    37.  
    38. //reboot command
    39. socket->write("reboot\r\n");
    40. socket->waitForBytesWritten(2000); // waiting the 2 seconds for the reboot command to take effect
    41.  
    42. qDebug() << "done";
    43. //closing connection
    44. socket->close();
    45.  
    46. }
    47. else {//if the program couldn't connect the program will output this in debug terminal
    48. qDebug() << "not connected";
    49.  
    50. }
    51. }
    To copy to clipboard, switch view to plain text mode 

    Here is what i am getting on the output terminal

    connected
    reading first "\xFF\xFB\x01"
    reading second "\xFF\xFB\x03"
    QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState
    reading third ""
    QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState
    reading fourth ""
    QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState
    done

    and i just can't seem to figure out what is wrong
    Last edited by anda_skoa; 8th May 2019 at 15:08. Reason: changed [qtclass] to [code]

Similar Threads

  1. Replies: 0
    Last Post: 8th May 2019, 11:32
  2. Qserialdevice 2.0 waitForBytesWritten halfduplex question
    By egadget1 in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2012, 22:11
  3. Replies: 1
    Last Post: 8th October 2010, 13:21
  4. QUdpSocket and UnconnectedState problem
    By RThaden in forum Qt Programming
    Replies: 0
    Last Post: 14th September 2009, 18:20
  5. waitForBytesWritten
    By smalls in forum Qt Programming
    Replies: 8
    Last Post: 1st March 2006, 17:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.