我需要將Qt遺留代碼從4.7轉換爲5.8,我在Qt Creator 4.2.1中出現編譯錯誤Clang 7.0(Apple)64bit 。'QUrl'中沒有名爲'addQueryItem'的成員 - 將Qt 4.7轉換爲5.8
展望.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
../src/prices/的頂部的.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>
錯誤的priceGetterTSP.cpp:86:12:錯誤:'QUrl'中沒有名爲'addQueryItem'的成員 params.addQueryItem(「fund」,properCaseSymbol); ~~~~~~^ ../src/prices/priceGetterTSP.cpp:87:12:錯誤:未在 'QUrl' params.addQueryItem( 「frommonth」,QString的名爲 'addQueryItem' 成員::數(beginQDate.month())); ~~~~~~^ ../src/prices/priceGetterTSP.cpp:88:12:error:'QUrl'中沒有名爲'addQueryItem'的成員 params.addQueryItem(「fromday」,QString :: number beginQDate.day())); ~~~~~~^ ../src/prices/priceGetterTSP.cpp:89:12:error:'QUrl'中沒有名爲'addQueryItem'的成員 params.addQueryItem(「fromyear」,QString :: number beginQDate.year())); ~~~~~~^ ../src/prices/priceGetterTSP.cpp:90:12:error:'QUrl'中沒有名爲'addQueryItem'的成員 params.addQueryItem(「tomonth」,QString :: number endQDate.month())); ~~~~~~^ ../src/prices/priceGetterTSP.cpp:91:12:error:'QUrl'中沒有名爲'addQueryItem'的成員 params.addQueryItem(「today」,QString :: number endQDate.day())); ~~~~~~^ ../src/prices/priceGetterTSP.cpp:92:12:error:'QUrl'中沒有名爲'addQueryItem'的成員 params.addQueryItem(「toyear」,QString :: number endQDate.year())); ~~~~~~^ 生成7個錯誤。 make:*** [priceGetterTSP.o]錯誤1 16:40:22:進程「/ usr/bin/make」退出,代碼爲2. 構建/部署項目時出錯mypersonalindex(套件:Desktop Qt 5.8。 0 clang 64bit)
OK ...那麼什麼是替換?
缺少什麼#include <>?
看看新的[QUrlQuery](http://doc.qt.io/qt-5/qurlquery.html)類。 – MrEricSir
@MrEricSir謝謝,**我的C++技能相當有限,你看到任何小的調整,可以將其從Qt4轉換爲Qt5 **。我懷疑我有使用QUrlQuery進行更改的背景。我在文檔中閱讀:類QUrl的以下成員已過時。提供它們是爲了保持舊的源代碼工作。我們強烈建議不要在新代碼中使用它們。錯誤在(已廢棄)void \t addQueryItem(const QString&key,const QString&value) – bullflag