I have a simple class that looks like this:
class QNetworkAccessManager;
class FontiDownloader : public QObject
{
Q_OBJECT
public:
FontiDownloader(QNetworkAccessManager* netManager);
void downloadFonti();
private:
QString m_dataLocation;
};
The implementation of downloadFonti()
is something like the following:
// the networkrequest is just a wrapper that makes a QNetworkRequest
auto nr = new NetworkRequest(m_netManager, this);
connect(nr, &NetworkRequest::completed, [this](QNetworkReply* reply){
// crash occurs here
QString dataLocation = m_dataLocation;
});
nr->send(QUrl(FONTI_URL), HttpMethod::GET);
When I call my lambda function inside downloadFonti()
, the program crashes and I have located the reason to be the line:
QString dataLocation = m_dataLocation;
I can see using the debugger that at the time of calling that line, m_dataLocation
is "not accessible". However, I cannot think why this would be the case.