我有问题,在下面的代码中,“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