我需要将Qt旧版代码从4.7转换为5.8,我在Qt Creator 4.2.1 Clang 7.0(Apple)64bit中遇到编译错误。在.cpp文件中查找QList<QByteArray> priceGetterTSP::downloadFile(const QString &symbol_, int beginDate_, int endDate_){ QNetworkAccessManager manager; QEventLoop loop; QNetworkRequest request(QUrl("http://www.fedsmith.com/tsp/csv.dailyfund.db.php")); QByteArray data; QUrl params; QDate beginQDate = QDate::fromJulianDay(beginDate_); QDate endQDate = QDate::fromJulianDay(endDate_);QString properCaseSymbol = symbol_.left(3).append(symbol_.right(symbol_.length() - 3).toLower()); params.addQueryItem("fund", properCaseSymbol); params.addQueryItem("frommonth", QString::number(beginQDate.month())); params.addQueryItem("fromday", QString::number(beginQDate.day())); params.addQueryItem("fromyear", QString::number(beginQDate.year())); params.addQueryItem("tomonth", QString::number(endQDate.month())); params.addQueryItem("today", QString::number(endQDate.day())); params.addQueryItem("toyear", QString::number(endQDate.year())); data.append(params.toString()); data.remove(0,1);QNetworkReply *reply = manager.post(request, data);QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));loop.exec();QList<QByteArray> lines;if (reply->error() == QNetworkReply::NoError) lines = reply->readAll().split('\n');delete reply;return lines;}看着.cpp的顶部#include "priceGetterTSP.h"#include <QString>#include <QList>#include <QByteArray>#include <QUrl>#include <QDate>#include <QNetworkAccessManager>#include <QNetworkRequest>#include <QNetworkReply>#include <QEventLoop>#include <historicalPrices.h>.cpp中的错误../src/prices/priceGetterTSP.cpp:86:12:错误:“ QUrl”中没有名为“ addQueryItem”的成员    params.addQueryItem(“ fund”,properCaseSymbol);    ~~~~~~ ^../src/prices/priceGetterTSP.cpp:87:12:错误:“ QUrl”中没有名为“ addQueryItem”的成员    params.addQueryItem(“ frommonth”,QString :: number(beginQDate.month()));    ~~~~~~ ^../src/prices/priceGetterTSP.cpp:88:12:错误:“ QUrl”中没有名为“ addQueryItem”的成员    params.addQueryItem(“ fromday”,QString :: number(beginQDate.day()));    ~~~~~~ ^../src/prices/priceGetterTSP.cpp:89:12:错误:“ QUrl”中没有名为“ addQueryItem”的成员    params.addQueryItem(“ fromyear”,QString :: number(beginQDate.year()));    ~~~~~~ ^../src/prices/priceGetterTSP.cpp:90:12:错误:“ QUrl”中没有名为“ addQueryItem”的成员    params.addQueryItem(“ tomonth”,QString :: number(endQDate.month()));    ~~~~~~ ^../src/prices/priceGetterTSP.cpp:91:12:错误:“ QUrl”中没有名为“ addQueryItem”的成员    params.addQueryItem(“ today”,QString :: number(endQDate.day()));    ~~~~~~ ^../src/prices/priceGetterTSP.cpp:92:12:错误:“ QUrl”中没有名为“ addQueryItem”的成员    params.addQueryItem(“ toyear”,QString :: number(endQDate.year()));    ~~~~~~ ^产生7个错误。制作:*** [priceGetterTSP.o]错误116:40:22:进程“ / usr / bin / make”以代码2退出。生成/部署项目mypersonalindex时出错(工具包:Desktop Qt 5.8.0 clang 64bit)好...那是什么替代品?缺少的#include 是什么? (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 您可以创建一个addQueryItem对象,然后在该对象上进行调用,而不是在QUrl对象上调用QUrlQuery。然后在网址上设置完成的查询QUrlQuery paramsQuery;paramsQuery.addQueryItem("fund", properCaseSymbol);// and so on..params.setQuery(paramsQuery);由于您不是将params用作URL,而是用作toString助手,因此您甚至可以尝试仅更改类型QUrlQuery params;并按原样保留大部分代码 (adsbygoogle = window.adsbygoogle || []).push({});
10-07 22:17