Qt开发笔记
Qt - Windodw识别设备插拔事件
Winodws系统消息结构:#include <qt_windows.h>
1 | LRESULT CALLBACK WindowProc( |
设备插入/拔出:#include <Dbt.h>
msg->wParam
Value | Meaning |
---|---|
DBT_DEVICEARRIVAL | A device or piece of media has been inserted and is now available. |
DBT_DEVICEREMOVECOMPLETE | A device or piece of media has been removed. |
设备接入类型:msg->lParam 强制转换
Value | Meaning |
---|---|
DBT_DEVTYP_DEVICEINTERFACE 0x00000005 |
Class of devices. This structure is a DEV_BROADCAST_DEVICEINTERFACE structure. |
DBT_DEVTYP_HANDLE 0x00000006 |
File system handle. This structure is a DEV_BROADCAST_HANDLE structure. |
DBT_DEVTYP_OEM 0x00000000 |
OEM- or IHV-defined device type. This structure is a DEV_BROADCAST_OEM structure. |
DBT_DEVTYP_PORT 0x00000003 |
Port device (serial or parallel). This structure is a DEV_BROADCAST_PORT structure. |
DBT_DEVTYP_VOLUME 0x00000002 |
Logical volume. This structure is a DEV_BROADCAST_VOLUME structure. |
CyAPI:官方lib使用MinGW编译,无法使用MSVC编译调用。
QString
QString hex to unsigned char
1 | unsigned char myBuffer[2]; |
QString 基本操作
在Qt5中,right()/left()/mid()
是深拷贝,返回一个字符串中的n个字符的字符串。rightRef()/leftRef()/midRef()
则是返回对其的引用。
- n > str.length : return null string / reference
- n < str.length : starting at the given position
- n = -1(default): return all string / reference
1 | QString str = "hello-world!"; |
QCharts
改变画笔颜色/宽度
- 单独指定画笔颜色+宽度
1 | QPen pen = series->pen(); |
- 继承系统默认颜色,在
chart->addSeries(series);
之后设置画笔1
2
3
4
5
6QChart *chart = new QChart();
chart->addSeries(series); // addSeries must be called first
QPen pen = series->pen();
pen.setWidth(1);
series->setPen(pen);
QSpinBox
按位数补齐0:重载QSpinBox - textFromValue
1 |
|
设置前缀/后缀/当前值
1 | ui->my_spinbox->setPrefix("0x"); |
QTabWidget
改变背景色
QtDesigner -> TabWidget ->styleSheet属性中设置:在样式表中用’#’指定对象,子对象将不会继承样式表
1 | #objectName {background-color: rgb(240,240,240);} |
Qt打包程序
打包程序的一些已知问题:https://cloud.tencent.com/developer/article/1516768
无法定位程序输入点?xxx@Qxxx@@xxxx@@@xxxxx于动态链接库xx.exe上
调整系统环境变量该编译环境的环境变量顺序靠前即可。
eg.Qt有MinGW+MSVC2015的两个环境编辑:如果用MSVC2015编译打包的环境,则将MSVC2015的环境变量的顺序置于MinGW之前(必要的时候,越靠前越好)
Qt进程与线程
Error
error C2001: newline in constant(Qt中文编码问题)
待补充
Warnings
narrowing conversion from unsigned int to int
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.