Important: Please read the Qt Code of Conduct -

Reddit Example failing

  • Hi, I'm trying to run the Reddit Example, but I'm running into the following error: QSslSocket::connectToHostEncrypted: TLS initialization failed
    qt.networkauth.replyhandler: TLS initialization failed
    qt.networkauth.oauth2: Unexpected call

    I'm unsure about what is actually failing here, since I do see the "Callback received. Feel free to close this page." text in my browser.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Which version of Qt are you using ?
    On which platform ?

    Based on you error, I would guess Windows, and if so you are likely missing OpenSSL. You can get it through the online installer.

  • I tried this in Windows (5.15.1) and WSL2 (Ubuntu 20 - 5.12.8).
    I'm getting a slightly different error on WSL2.

    What do I need to do to enable the OpenSSL in the example?

  • Lifetime Qt Champion

    As I suggested above: install it using the online installer.

  • Yes, obviously. I did that.
    I'm asking what do I need to change in the project, so it links and enables OpenSSL?

  • Lifetime Qt Champion

    There's no linking to be done. OpenSSL is dynamically loaded at run time. One thing you can to is to copy the dlls in the same folders as your application.

    The other is to modify the PATH environment variable in the Run part of the Project panel and add the folder that contains the dlls to it.

    By the way, which compiler are you using ?

  • I'm still seeing this error in the output:

    qt.networkauth.oauth2: Unexpected call

    But it did succeed authenticating. I'm using Mingw.
    OK, so this at least works on Windows. Now to make it work on WSL2/Linux.

  • Lifetime Qt Champion

    What error are you getting on Linux ?

  • On Linux I'm struggling with the entire process. I can't figure out where the redirect_uri is comming from.

    Because it's not generated from QOAuthHttpServerReplyHandler. If I manually change the URL to point to the correct IP i get qt.networkauth.oauth2: Error: invalid_grant, but I think that is expected.

  • Lifetime Qt Champion

    The URL is set in your Reddit application configuration on the website.

  • Well, then something is broken in Qt. Because the redirect_uri definitely does not match what I set in my Reddit app.

  • @HappyCerberus Please note that openSSL redistributed with Qt is for MSVC only. For use with MinGW you'd need to find precompiled binaries build with MinGW, version (or 1.1.1.d), respectively x86 or x64. Or build them yourself.

  • @artwaw So, what you are saying is that the single case that I actually managed to get working is one that should not work :-D This is getting better and better :-)

  • @HappyCerberus It is a bit of a mystery for me too :) But I learned the hard way the first time they included OpenSSL in Qt and since then I don't rely this particular source.

  • @HappyCerberus I've de-dusted my old problems I had with SSL supplied via onlineinstaller - here goes the summary:

    • I compile with MinGW on Windows. Always have been.
    • once OpenSSL became available I was very happy, since it should simplify things. I began to use it but users reported to me that on some machines it doesn't work.
    • I've spent quite some time debugging until I took a look into libraries provided. They're compiled with MSVC so they need MSVC libraries to run. If you have them installed, everything will work just fine. So if it worked, it worked but some of my users have not had those libs installed.
    • Since then I stopped using bundled OpenSSL, as it is just potential additional overhead and more dependencies.

    So if it worked for you, you simply had those Microsoft runtime libraries installed. But I'd check with dependency free MinGW compiled SSL libs too, just to be sure.

  • @artwaw Yeah, my problem now is that it doesn't work on Linux, and I suspect that it will not work because of the redirect_uri.

  • @HappyCerberus That's beyond my area of experience, I am afraid. Hopefully more experienced colleagues here can be of help.

  • Lifetime Qt Champion

    Do you get the same issue with a "classic" Linux rather than WSL2 ?

  • Yeah, unfortunately the redirect_uri is again wrong and when I manually change it I get:

    qt.networkauth.oauth2: Unexpected call
    qt.networkauth.oauth2: Error: invalid_grant

Log in to reply