为什么我不能为我的 QTcpServer 设置特定地址?
Why I can't set a specific address for my QTcpServer?
我只想用一个特定的地址设置我的QTcpServer。我已经用这段代码试过了,但它不起作用...
server.listen(QHostAddress::setAddress("127.0.0.1"),8888);
这是错误:
Cannot call member function 'bool QHostAddress::setAddress(const QString&)' without object
server.listen(QHostAddress::setAddress("127.0.0.1"),8888);
^
谁能帮我?
Cannot call member function 'bool QHostAddress::setAddress(const QString&)' without object
该错误告诉您 setAddress 不是一个静态方法,您必须在对象上调用它:
QHostAddress adr;
adr.setAddress("...");
在您的情况下,您可以只将 QHostAddress 构造函数与字符串参数一起使用:
server.listen(QHostAddress("127.0.0.1"),8888);
相关文章:
- 循环中的变量被设置为下一个数组的元素始终具有相同的内存地址?
- C 指针设置为地址,但莫名其妙地指出了程序的不同部分中的不同值
- 如何设置指针的内存地址
- 如何在NS3中设置节点的IP地址和数据?
- C 将值设置为特定地址
- 设置成员 GlobalCEFApp->OnWebKit使用函数地址初始化 C++生成器
- 将结构元素地址设置为C 中的null(单链接列表)
- 在C++中设置节点的内存地址
- 定义一个C宏并将内存地址设置为用C和C++编写的结构成员
- 从指针数组的元素传递地址以设置另一个指针地址
- mfc c++通过编辑控件设置另一个应用程序的HWND地址
- 如何将数组中元素的地址设置为指向另一个数组中的特定元素
- 如何将源IP地址设置为0.0.0.0
- 正在将IPv4/IPv6地址和端口设置为sockaddr_storage结构
- 在 Boost ASIO 中,如何设置源 IP 地址以模拟其他服务器的 IP 地址?
- 为什么我不能为我的 QTcpServer 设置特定地址?
- 将指针设置为 nullptr 是否会影响指向同一地址的其他指针
- 在c或c++中,如何区分在内存地址上设置的0和由于该地址未初始化而设置的0
- 设置随机内存地址的值
- 在 Visual Studio 2005 中对取消引用的指针的地址设置数据断点