Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtcpSocket—QIODevice.write() sometimes return -1
Forum Updated to NodeBB v4.3 + New Features

QtcpSocket—QIODevice.write() sometimes return -1

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 746 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hansflying
    wrote on last edited by koahnig
    #1

    Dear all,

    I set up a QtcpSocket to test my TCP based communication as follows:

    QtcpSocket ipSocket = new QtcpScoket(this);
    ipSocket->connectToHost(HostName, dataPort);
    if(ipSocket->waitForConnected(5000ms))
    {
    	.........................
    }
    Else
    {
    	.......................
    }
    

    it works fine.

    then I want to write some message to the TCP with following codes:

    QIODevice m_ioDevice;
    if((this->m_ioDevice != 0) && (this->m_ioDevice->isWritable())
    {
    	if(This.m_ioDevice->write(msg) == msg.count())
    	{
    		.........................
    	}
    	Else
    	{
    		........................
    	}
    }
    

    it also works in most time. But sometimes the message can not be written to the IODevice, and the function This.m_ioDevice->write(msg) return -1.

    I am not sure:

    1. what does it mean when This.m_ioDevice->write(msg) returns -1 ?
    2. why my code works fine in most time, only sometime the problem occurs?
    3. how could I solve this problem?

    thanks a lot for any of your suggestion and reply

    best regards,
    hansflying

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Welcome to devnet

      I have added editor markdown tags for your code block. This makes it easier to read. Please have a look to the "Editor markdown tags" at the end of this page.

      You can call error() and errorString(). From experience I guess that the connection broke down for whatever reason.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hansflying
        wrote on last edited by
        #3

        thank you koahnig a lot!!

        I will try your suggestion.

        But the problem occurs sometimes. Whatever we will check it.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved