lineEdit = new QLineEdit(this);
QString ip_dest;
udpSocket=new QUdpSocket(this);
port=69; //tftp
ip_dest =lineEdit->text();
udpSocket->bind(ip_dest,port);
报错 :G:\qt\projects\test\test125\mainwindow.cpp:24: error: C2664: “bool QAbstractSocket::bind(const QHostAddress &,quint16,QAbstractSocket::BindMode)”: 不能将参数 1 从“QString”转换为“const QHostAddress &”
原因如下: 无法从“QString”转换为“const QHostAddress”
没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
你的字符串不能之间转换为QAddress
需要这么写
udpSocket->bind(new QHostAddress(ip_dest),port);
bind 的代码中哪里?没有看到。
udpSocket = new QUdpSocket(this);//创建一个QUdpSocket类对象,该类提供了Udp的许多相关操作
port = 45454;
//此处的bind是个重载函数,连接本机的port端口,采用ShareAddress模式(即允许其它的服务连接到相同的地址和端口,特别是
//用在多客户端监听同一个服务器端口等时特别有效),和ReuseAddressHint模式(重新连接服务器)
udpSocket->bind(port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
//readyRead()信号是每当有新的数据来临时就被触发
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()));