1

I migrated some code from Qt 5.6.0 to Qt 5.12.0 both compiled with Visual Studio 2015. It has some code using QtBluetooth for regular (no "low energy") bluetooth. With 5.6.0, this used to work perfectly.

With Qt 5.12.0, my app won't load. It reports missing API-MS-WIN-CORE-WINRT-L1-1-0.DLL and API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL. I don't understand why those WinRT files are required. Dependency Walker for QtBluetooth.dll reports those libraries as missing.

I tried both with Qt 5.12.0 compiled my selft and downloaded as part of a QtCreator install. I tried both Windows 7 and 10, Windows 10 works smartly. Always getting this error and I found no information about where to find those libraries or how to have QtBluetooth not use them.

What should I do to be simply able to run a QtBluetooth based app under Windows?

Edit: Submitted Qt bug: https://bugreports.qt.io/browse/QTBUG-73272

jpo38
  • 20,821
  • 10
  • 70
  • 151
  • Using Qt-bluetooth on windows 7 always results in missing libraries errors for me. For non-LE bluetooth I'm using the windows com-serial-interface instead. Not to say this is correct, IMHO it should fail at runtime with an exception stating that no BT-backend is available. It's a headache for me to manage a windows 7 and windows 10 version. Please let me know if you do find out more on this. – markus-nm Jan 25 '19 at 11:35
  • I observe that Qt 5.6 loads for both Win7 and Win10 and Qt 5.12.0 loads for none of them... – jpo38 Jan 25 '19 at 11:47

1 Answers1

0

If you have no requirement for low-energy and can bother your users to pair the device using the windows system settings dialog, then I'd recommend to write wrapper code for windows which does not use QtBluetooth. I.e.

#include <Windows.h>

class win_con {
    ....

    HANDLE hcon;
    COMMTIMEOUTS *timeouts;

    // i.e. com_port = L"\\\\.\\COM1"; 
    void open_com(std::wstring com_port, int read_timeout, int write_timeout)
    {

        hcom = CreateFile(com_port.c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, 
            OPEN_EXISTING, 0, nullptr);
        if (hcom == INVALID_HANDLE_VALUE) ...

        timeouts = new COMMTIMEOUTS();
        memset(timeouts, 0, sizeof(COMMTIMEOUTS));
        timeouts->ReadTotalTimeoutConstant = read_timeout;
        timeouts->WriteTotalTimeoutConstant = write_timeout;
        if (!SetCommTimeouts(hcom, timeouts)) ...

    }

    void write_data(QString data)
    {
        std::string stddata = data.toStdString();
        DWORD numwritten = 0;
        if (!WriteFile(hcom, stddata.c_str(),
                static_cast<DWORD>(stddata.length()), &numwritten, nullptr)) {
            ...
        }
    }

    QString read_data(int len)
    {
        #define BUFFER_SIZE 256
        char buffer[BUFFER_SIZE];
        DWORD data_read = 0;
        if (BUFFER_SIZE < len) ....
        for (int i = 0; i < BUFFER_SIZE; i++)
            buffer[i] = 0;

        ReadFile(hcom, &buffer, len, &data_read, nullptr);

        if (read == 0) ...
        if (read < len) ...

        return QString(buffer);
    }
}
markus-nm
  • 805
  • 5
  • 8
  • Yes, that's an alternative. Actually you could even use `QSerialPort` to do that. Low energy isn't available anyway for Windows. – jpo38 Jan 27 '19 at 09:10
  • If you're using Qt 5.10+ then low-energy is available on Windows 10 (with and without UWP). It's just that the application won't run on Windows 7 because of missing DLLs even though it should fail at runtime. – markus-nm Jan 28 '19 at 18:35