gpt4 book ai didi

c++ - Qt中需要释放slot参数的资源吗?

转载 作者:行者123 更新时间:2023-11-30 01:09:38 25 4
gpt4 key购买 nike

举个例子,看看这段代码:

QNetworkRequest request(mResultsURL); //our server with php-script

connect(mNetworkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onUploadFinished(QNetworkReply*))); //This slot is used to debug the output of the server script
mNetworkManager->post(request,data);

以及对应的接收槽:

void MyApp::onUploadFinished(QNetworkReply *reply){

QJsonObject root = QJsonDocument::fromJson(reply->readAll()).object();

// do some work
}

所以我的问题是:我需要添加吗

delete reply;

到函数结束?还是由 Qt 自动处理?

最佳答案

根据docs ,您需要释放资源,但不能删除槽内的回复。您需要调用deleteLater()相反:

Note: After the request has finished, it is the responsibility of the user to delete the QNetworkReply object at an appropriate time. Do not directly delete it inside the slot connected to finished(). You can use the deleteLater() function.

[...]

Note: Do not delete the reply object in the slot connected to this signal. Use deleteLater().

关于c++ - Qt中需要释放slot参数的资源吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39949755/

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