如何把LineEdit中的 IP地址存到数组里,附我写的代码

weixin_38078058 2019-09-19 12:52:39
QByteArray ip=ui->setipLineEdit->text().toLatin1();    QString str= ip.toHex().data();    str = str.toUpper();    QByteArray aa;    aa.resize(4);    aa[0] = str.mid(0,2);    aa[1] = str.mid(3,2);    aa[2] = str.mid(6,2);    aa[3] = str.mid(9,2);编译出错,求助!!!!!!!!!!!!!
...全文
98 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38088352 2019-09-19
  • 打赏
  • 举报
回复
QByteArray ip=ui->setipLineEdit->text().toLatin1();之后ip会被赋值为一个类似255.255.255.255的字符串吧    QString str= ip.toHex().data();然后你给他来了个toHex(),之后str的返回值你知道是什么吗?大概会是3235352e3235352e3235352e323535的字符串因为'2'=0x32,'5'=0x35,'.'=0x2e这样ip.toHex().data()返回的就是一个那一串数字字符串的c串,然后赋值给str……难道不感觉奇怪么……
weixin_38091479 2019-09-19
  • 打赏
  • 举报
回复
那怎样才能转成十六进制 ,分别存到数组里?
weixin_38117299 2019-09-19
  • 打赏
  • 举报
回复
引用第3楼roywillow于2012-04-03 08:29发表的  :QByteArray ip=ui->setipLineEdit->text().toLatin1();之后ip会被赋值为一个类似255.255.255.255的字符串吧    QString str= ip.toHex().data();然后你给他来了个toHex(),之后str的返回值你知道是什么吗?大概会是3235352e3235352e3235352e323535的字符串....... 大侠,请点拨!
weixin_38126752 2019-09-19
  • 打赏
  • 举报
回复
以解决 ,鸣谢 roywillow !!
weixin_38127967 2019-09-19
  • 打赏
  • 举报
回复
QString ip=ui->setipLineEdit->text();    QStringList  list1= ip.split(".");    QByteArray aa;    aa.resize(9);    aa[0] = 0x02;    aa[1] = 0x02;    aa[2] = 0x05;    aa[3] = list1.at(0).toInt();    aa[4] = list1.at(1).toInt();    aa[5] = list1.at(2).toInt();    aa[6] = list1.at(3).toInt();    aa[7] = aa[3]^aa[4]^aa[5]^aa[6];    aa[8] = 0x03;    tcplink->write(aa);
weixin_38080213 2019-09-19
  • 打赏
  • 举报
回复
顶   下
weixin_38087646 2019-09-19
  • 打赏
  • 举报
回复
str.mid(0,2)出来的值不是直接可以放到QByteArray中去的。

435

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧