Search code examples
c++stringqttcpsend

Qt "tcpserver->write(string)"


i have a very simple question here, How can i send a string with

tcpserver->write(string);

I tried:

tcpserver->write("string") 

and it works, but if i want to input a string in there, i get a "no matching function to call to 'QtcpSocket::write(QString)'" error,

so i tried converting the string to "data" and then send it, but i got a ton of errors...

And my question is: How can i easly send a string thru my tcpserver?

(I should also mention, that i am very new to programming)


Solution

  • You need to convert string to QByteArray, for example:

    tcpserver->write(string.toLocal8Bit());