c++ - 在 Windows 7 下无法加载 QtBluetooth 5.12.0
问题描述
我将一些代码从 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 文件。Dependency WalkerQtBluetooth.dll
将这些库报告为缺失。
我尝试使用 Qt 5.12.0 编译我的 selft 并作为QtCreator
安装的一部分下载。我尝试了 Windows 7 和 10,Windows 10 运行良好。总是收到此错误,我没有找到有关在哪里可以找到这些库或如何QtBluetooth
不使用它们的信息。
我应该怎么做才能QtBluetooth
在 Windows 下简单地运行基于应用程序?
编辑:提交的 Qt 错误:https ://bugreports.qt.io/browse/QTBUG-73272
解决方案
如果您不需要低能耗并且可以打扰您的用户使用 Windows 系统设置对话框配对设备,那么我建议为不使用 QtBluetooth 的 Windows 编写包装器代码。IE
#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);
}
}
推荐阅读
- random - 生成 N 个具有 X 位的随机数,使得差(从上到下减去的数字)为正
- sql - SQL Server 比较 (dev) 表列内容与 (prod) 表列内容
- r - R中的右对齐列
- mysql - 无法获取日期时间小于系统日期的记录
- ios - 视觉框架:在跟踪用户的面部时,如何让图像(如帽子)与面部同步移动?
- javascript - javascript密码输入验证启动模式
- sql - 如何通过查询获取 SQL 表外键类型
- angular - 如何在Angular 6的OwlDateTime中设置手动输入的日期
- javascript - 如何避免在 javascript for 循环中重复代码?
- c# - Selenium - 调用项目 DLL 来运行测试用例 c# 问题