QNetwork停止连接并检索数据

时间:2018-03-27 13:27:13

标签: c++ qt

我想在阅读网址时在QNetwork上超时。如果读取数据的时间超过30秒(它没有超时,则服务器未关闭,连接未断开,连接未关闭,连接仍处于活动状态且我仍在接收数据)。我需要在X秒后停止+关闭QNetwork,即使服务器仍在运行并发送数据。我怎么能这样做?

2 个答案:

答案 0 :(得分:0)

您可以使用QTimer纯虚拟广告位QNetworkReplyabort()单纯模式连接QTimer timer; timer.setSingleShot(true); // connect the timer to the reply connect(&timer, SIGNAL(timeout()), &networkReply, SLOT(abort()))); // start your timer timer.start(30000);

close()

要获取当前数据,请在执行中止方法时执行此操作,然后调用QNetworkReply QIODevicereadAll(),因此您可以使用PHP (default value): uses internal PHP mail function Sendmail : uses sendmail mailer SMTP : based on SMTP relaying. Use this setting when you are running LimeSurvey on a host that is not your mail server Make sure that you are using your SMTP configured email (Global settings -> Email settings) if you use SMTP, otherwise there might be a chance that the following error is displayed: 'SMTP -> ERROR: RCPT not accepted from server: 553 5.7.1 : Sender address rejected: not owned by user' Qmail : Set this if you are running the Qmail mailer 方法。

答案 1 :(得分:0)

数据的接收可以用作已建立连接的指示符。这可以用来触发超时。

因此:

def get_mylogger():
    # get logger
    fmt = '%(asctime)-15s %(levelname)-4s %(message)s'
    datefmt = '%Y-%m-%d %H:%M:%S'

    mylogger = logging.getLogger()
    mylogger.setLevel(logging.INFO)

    # log_path = "/opt/spark/logs/pyspark/"
    log_path = "H:\upupw\www\spark\logs\pyspark"
    if not os.path.exists(log_path):
        os.makedirs(log_path)
    log_file_name = 'spark.log'
    log_name = os.path.join(log_path, log_file_name)

    # TimedRotatingFileHandler
    timer = TimedRotatingFileHandler(log_name, when='D')

    formatter = logging.Formatter(fmt, datefmt=datefmt)
    timer.setFormatter(formatter)
    mylogger.addHandler(timer)

    return mylogger