2017-01-23 36 views
0

"QSslCertificate :: fromPath"の下のコードで、指定したファイルが見つかりませんでしたが、下のfileExists関数では、ファイルが結局存在することがわかります。この問題は、開発用PCとは異なるPCでアプリケーションを実行しようとした場合にのみ発生します。私はWindows 10 64ビットで開発し、テスト用のPCはWindows 7 64ビットです。私は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に証明書を読み、上の1つを通過したときに、私のWindows 10開発者向けPC上ですべてがまだ正常に動作しながら、その後、私の接続機能は、そのWindows 7のPC上で何もしません。

また、私が何をしても一貫してTLSハンドシェークエラーを出すPCがあります。 3台のPC、3台の結果、それはうんざりです。

答えて

0

私は私の場合、解決策を見つけた:私は私のディレクトリにOpenSSLライブラリlibeay32.dllとssleay32.dllをを追加しませんでしたexeが存在します。

0

あなたのコードは正常に見え、私のLinuxシステム上で問題なく動作します。あなたは、相対パスを確認するか、単にのQFileInfo経由で証明書を設定してみてください:

QLatin1String rootCApath = QLatin1String("./ssl/rootCA.crt"); 
QFileInfo temp(rootCApath); 
QString tempssl; 
QDir dir ;//try to set dir also if this does not work dir("/home/foo/yourapppath/"); 

tempssl=dir.relativeFilePath("./ssl/rootCA.crt"); 
static QList<QSslCertificate> cert = QSslCertificate::fromPath(tempssl); 

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); 
} 
+0

QCoreApplication :: applicationDirPath()にQDirディレクトリを設定しても、残念ながらこれは役に立ちませんでした。 – Alex

関連する問題