我将一些代码从Qt 5.6.0迁移到Qt 5.12.0,两者都是用Visual Studio 2015编译的。它有一些使用QtBluetooth的普通(没有“低能量”)蓝牙的代码。在5.6.0中,这曾经完美地工作过。
使用Qt 5.12.0,我的应用程序将无法加载。它会报告缺少API-MS-WIN-CORE-WINRT-L1-1-0.DLL和API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL。我不明白为什么需要这些WinRT文件。QtBluetooth.dll的Dependency Walker将这些库报告为缺失。
我用Qt 5.12.0编译了我的selft并作为QtCreator安装的一部分下载了这两个版本。我试过Windows7和Windows10,Windows10运行得很好。总是收到这个错误,而且我没有找到关于在哪里可以找到这些库的信息,或者如何让QtBluetooth不使用它们。
我应该怎么做才能简单地在Windows下运行基于QtBluetooth的应用程序?
编辑:提交的Qt错误:https://bugreports.qt.io/browse/QTBUG-73272
发布于 2019-01-26 19:47:13
如果你对低能耗没有要求,并且可以麻烦你的用户使用windows系统设置对话框来配对设备,那么我建议为不使用QtBluetooth的windows编写包装器代码。也就是说。
#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);
}
}https://stackoverflow.com/questions/54361787
复制相似问题