Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert text to quint16

Tags:

qt

qstring

I want to convert a QString to quint16. I'm reading a port number from a textBox, and I need to convert it into quint16 format for my UDP socket writeData() function.

Is it easier to store the text in a QByteArray then convert it? If so, I've only found the modifier toUint(), but nothing for quint16.

like image 434
Jedi Engineer Avatar asked Mar 19 '14 20:03

Jedi Engineer


1 Answers

According to the Qt docs, quint16 is just a typedef for unsigned short - so you can simply use QString::toUShort.

like image 178
Flopp Avatar answered Sep 21 '22 11:09

Flopp