lxn / walk

A Windows GUI toolkit for the Go Programming Language
Other
6.79k stars 885 forks source link

how to append text to textedit #680

Closed Assassintears closed 4 years ago

Assassintears commented 4 years ago

I code a tcp client desktop app, want to receive string data from the server and put it to textedit. Now the error description likes bellow when I calling AppendText of textedit.

image

image

image

kjk commented 4 years ago

The error tells you that str contains a byte 0 in it (which is not a valid character). Most likely this happens because Read() doesn't fill the whole by and the rest of it is filled with default 0 bytes. Try:

n, err := tcp.conn.Read(by)
...
tcp.Ch <- string(by[:n])

It'll still fail if the bytes sent on tcp connection contains 0 byte. You might want to filter invalid chars to guard against that.

Assassintears commented 4 years ago

@kjk yes, I fixed the problem with your method, thank you very much