QT总算是良心发现,从5.15版本开始支持了QNetworkRequest的超时设置,再也不用自己造轮子了!
void QNetworkRequest::setTransferTimeout(int timeout = DefaultTransferTimeoutConstant)
Sets timeout as the transfer timeout in milliseconds.
Transfers are aborted if no bytes are transferred before the timeout expires. Zero means no timer is set. If no argument is provided, the timeout is QNetworkRequest::DefaultTransferTimeoutConstant. If this function is not called, the timeout is disabled and has the value zero.
This function was introduced in Qt 5.15.