QT开发备注

1.QJsonObject与QJsonValue

QJsonObject的底层实现是map,默认状态下,会根据key值对成员进行排序。不过网络通信的场景下,顺序并不会影响与服务器的正常通信。

QJsonValue本身只有七种type,参考官方文档QJsonValue Class | Qt Core 5.15.3

ConstantValueDescription
QJsonValue::Null0x0A Null value
QJsonValue::Bool0x1A boolean value. Use toBool() to convert to a bool.
QJsonValue::Double0x2A double. Use toDouble() to convert to a double.
QJsonValue::String0x3A string. Use toString() to convert to a QString.
QJsonValue::Array0x4An array. Use toArray() to convert to a QJsonArray.
QJsonValue::Object0x5An object. Use toObject() to convert to a QJsonObject.
QJsonValue::Undefined0x80The value is undefined. This is usually returned as an error condition, when trying to read an out of bounds value in an array or a non existent key in an object.

 

根据文档可以明显得知,totype()函数仅针对type产生正确的返回,例如:对type = bool的执行toBool()正确,对type = double 的执行toBool()错误。

2.QMessageBox的自动关闭

创建messageBox的时候,如果使用QMessageBox::warning(...)或者QMessageBox::information(...)就无法使用QTimer自动关闭了。这里同样参考,官方文档的介绍QMessageBox Class | Qt Widgets 5.15.3

Opens a warning message box with the given title and text in front of the specified parent widget.

The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButtonQMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

The message box is an application modal dialog box.

Warning: Do not delete parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QMessageBox constructors.

文档里没有明确说明,但是这四个函数(剩下的是question,information,critical)我们在使用timer,指定accept或者别的什么槽函数的时候实际上并没有,连接到这四个函数生成的messageBox,因此就无法自动关闭。实际上调试过程中,我这边明确复现了一个场景:

warning生成了一个窗口,同时还有另一个不知道谁生成的窗口产生,没有抬头没有内容没有按钮,比较奇怪。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值