2

我只想用一个特定的地址设置我的 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);
                                                 ^

谁能帮我?

4

1 回答 1

4
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);
于 2016-02-20T22:51:14.183 回答