精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
锐英源精品原创,禁止转载和任何形式的非法内容使用,违者必究
近期学员实践QT项目,遇到如下问题:
C:\Users\Johnaon\Documents\untitled1\httppostrequest.cpp:15: error: request for member 'setHeader' in 'request', which is of non-class type 'QNetworkRequest(QUrl)' C:/Users/Johnaon/Documents/untitled1/httppostrequest.cpp:15:13: error: request for member 'setHeader' in 'request', which is of non-class type 'QNetworkRequest(QUrl)' 15 | request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader,
看对应的头文件,也有setHeader函数。
setHeader(knownHeaders, const QVanant &): void QHttpHeaders headers()const; void setHeaders(const QHttpHeaders &newHeaders);void setHeaders(QHttpHeaders &&newHeaders); //"cooked" headers QVariant header(KnownHeaders header)const;void setHeader(KnownHeaders header, const QVariant &value); // raw headers:Hif QT_NETWORK_REMOVED_SINCE(6, 7) bool hasRawHeader(const QByteArray &headerName) const;tendif bool hasRawHeader(QAnyStringView headerName)const;QList<QByteArray>rawHeaderList()const; QByteArray rawHeader(const QByteArray &headerName) const;
这问题在类对象上,不是setHeader上,QNetworkRequest(QUrl)不是一个有效的类对象,也就是说QNetworkRequest(QUrl)没有对应的构造函数。这反应了基础知识在复杂环境下不能正常使用,不敢怀疑自己的错误想法。