简体   繁体   English

QSerialPortInfo isValid() 和 isBusy()

[英]QSerialPortInfo isValid() and isBusy()

QSerialPortInfo class has const methods isValid () (deprecated since 5.2) and isBusy () (deprecated since 5.6). QSerialPortInfo类具有常量方法isValid () (自 5.2 起已弃用)和isBusy () (自 5.6 起已弃用)。 They both seem to work but QT documentation does not provide with info whether they should be replaced with isNull () or state of QSerialPortInfo object should be checked some other way.它们似乎都可以工作,但 QT 文档没有提供是否应该用isNull () 替换它们或应该以其他方式检查QSerialPortInfo对象的状态的信息

Can anyone please tell me actual way to check serial port availability?谁能告诉我检查串口可用性的实际方法?

I am using the same function call and it appears to work, so I was wondering why the function is obsolete.我正在使用相同的函数调用并且它似乎可以工作,所以我想知道为什么该函数已过时。 Turns out, the function opens the port in question, see bug report here .事实证明,该函数打开了有问题的端口,请参阅此处的错误报告。 This side effect seems to be the reason why it was marked obsolete and deprecated.这种副作用似乎是它被标记为过时和弃用的原因。

If that side effect is okay with you (and the reported "other issues" by the maintainer in the bug report), then that appears to be an okay way to get done what you're asking for.如果这种副作用对您没有问题(以及维护者在错误报告中报告的“其他问题”),那么这似乎是完成您所要求的事情的好方法。

With reference to the documentation , both isValid() and isBusy() are obsolete and not recommended to be used in new code.参考文档isValid()isBusy()都已过时,不建议在新代码中使用。

Quote from documentation (emphasis mine):引用文档(强调我的):

They are provided to keep old source code working.提供它们是为了保持旧的源代码工作。 We strongly advise against using them in new code.我们强烈建议不要在新代码中使用它们。

The See also section points to isNull() method so it should be used.另请参阅部分指向isNull()方法,因此应该使用它。

See commit .请参阅提交

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM