View Full Version : How to convert from QString to quint16 ?
probine
31st March 2006, 08:34
How do I convert from QString to quint16 ?
zlatko
31st March 2006, 08:39
QString::number doesnt help?
jpn
31st March 2006, 08:44
QString str("1234");
QTextStream ts(&str);
quint16 num = 0;
ts >> num;
probine
31st March 2006, 08:50
I have a QLineEdit:
QLineEdit *lePort = new QLineEdit();
lePort->setText("3000");
In my tcpSocket I need to connect:
QTcpSocket *tcpSocket = new QTcpSocket();
tcpSocket->connectToHost(QHostAddress("127.0.0.1"), quint16(2000));
In stead of having the quint16(2000) I would like to have the value of lePort. I tried
tcpSocket->connectToHost(QHostAddress("127.0.0.1"), QString::number(lePort->text()));
but it doesn't work.
zlatko
31st March 2006, 09:00
Actually i see that you want string - > int not int->string as i understad before.
Try next
tcpSocket->connectToHost(QHostAddress("127.0.0.1"),lePort->text().toShort());
gadnio
31st March 2006, 09:00
QString::number() makes a QString from a number.. read the docs first.
Use QString::toInt(), QString::toUInt(), etc.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.