我有問題,在下面的代碼中,「QSslCertificate :: fromPath」找不到我指定的文件,但是當我檢查它時使用下面的fileExists函數,它告訴我該文件畢竟存在。只有當我嘗試在與我的開發PC不同的PC上運行我的應用程序時,纔會出現此問題。我在Windows 10 64 Bit上開發,測試PC是Windows 7 64 Bit。我使用QT 5.4.0。我究竟做錯了什麼?Qt:QSslCertificate :: fromPath沒有找到我的文件,但QFileInfo發現它
void MyClass::init()
{
// ... some other init code
QLatin1String rootCApath = QLatin1String("./ssl/rootCA.crt");
if (fileExists(rootCApath))
log("File exists"); // This is just a log function for displaying messages in the GUI.
else
log("File doesn't exist");
static QList<QSslCertificate> cert = QSslCertificate::fromPath(rootCApath);
if(cert.size()==1)
{
ssl_configuration.setCaCertificates(cert);
m_webSocket.setSslConfiguration(ssl_configuration);
}
else
{
QString s = "Server certificate not found. Size is " + QString::number(cert.size());
log(s);
}
}
bool MyClass::fileExists(QString path) {
QFileInfo check_file(path);
// check if file exists and if yes: Is it really a file and no directory?
return check_file.exists() && check_file.isFile();
}
編輯:當我閱讀證書到一個QByteArray中,並傳遞一個,那麼我的連接功能不Windows 7的PC機上做任何事情,而在我的Windows 10開發PC一切仍然正常工作。
此外,還有另一臺PC始終給我TLS握手錯誤,無論我做什麼。 3臺電腦,3個結果,令人沮喪。
不幸的是,這並沒有幫助,無論我是否將QDir dir設置爲QCoreApplication :: applicationDirPath()。 – Alex