如何使用Qt检查计算机的状态? [英] how to check computer's state using Qt?

查看:160
本文介绍了如何使用Qt检查计算机的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在局域网中获取计算机的状态... 考虑过使用QTcpSocket,但效果并不理想,因为port也应该插入为:

i'm trying to get computer's state in my LAN... thought about using QTcpSocket but it's not realy effective since port also should be inserted as:

socket->connectToHost("hostName", portNumber);
if (socket->waitForConnected(1000))
     qDebug("Connected!");

有人可以妖怪我一个更好的方法来检查计算机是否响应吗?

can anyone demonstare me a better way to check if computer is responding ?

推荐答案

ping

int exitCode = QProcess::execute("ping", QStringList() << "-c1" << "hostname");
if (0 == exitCode) {
    // it's alive
} else {
    // it's dead
}

参数可能会有所不同.例如,我相信它将在Windows上为ping -n 1 "hostname".该示例应适用于大多数非Windows版本.

Arguments may vary. For example, I believe it would be ping -n 1 "hostname" on Windows. The example should work on most non-Windows versions.

这篇关于如何使用Qt检查计算机的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆