gpt4 book ai didi

qt - 连接到QNetworkReply::错误信号

转载 作者:行者123 更新时间:2023-12-04 07:04:52 26 4
gpt4 key购买 nike

我正在为Qt5使用新的connect语法。 QNetworkReply有一个名为error的信号,还有一个名为error的函数。尝试连接信号时,这会导致问题:

connect(reply, &QNetworkReply::error, this, &MyClass::error);

error C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)' : cannot convert parameter 2 from 'overloaded-function' to 'const char *' Context does not allow for disambiguation of overloaded function



如何告诉编译器(MSVC)我要连接到信号而不是功能?

最佳答案

您需要手动强制转换函数指针以寻址正确的函数:

connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &MyClass::error);
这是对重载函数使用新语法的 noted结果:

cons:

Very complicated syntax in cases of overloads?


P.S.您可以在上面的链接中找到类似的示例:
 QObject::connect(socket, static_cast<void (QTcpSocket::*)(QAbstractSocket::SocketError)>(&QAbstractSocket::error), [socket] (QAbstractSocket::SocketError) {
qDebug()<< "ERROR " << socket->errorString();
socket->deleteLater();
});

关于qt - 连接到QNetworkReply::错误信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14992668/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com