IP アドレスに対して ping を実行しています。ping 操作が行われていることを QMessageBox に表示したいと考えています。その後、レスポンスを受信するか、1秒のタイムアウトが発生したら、QMessageBoxを閉じたいと思います。
コード:
int status;
QByteArray command;
QMessageBox myBox(QMessageBox::Information, QString("Info"), QString("Checking connection"), QMessageBox::NoButton, this);
command.append("ping -w 1 172.22.1.1");
status=system(command);
myBox.setStandardButtons(0);
myBox.exec();
if (0==status){ // Response received
// Some stuff here...
myeBox.setVisible(false);
}
else { // Timeout
// Some other stuff here...
myBox.setVisible(false);
}
私の推測では、このタスクにはスレッドを使用する必要があるかもしれませんが、私は Qt の初心者なので、問題は他の場所にある可能性があります。
編集: @atamanroman が示唆したように、Qt リファレンスで説明されているように、シグナル void QProcess::finished ( int exitCode, QProcess::ExitStatus exitStatus ) [signal] を使用して、QProcess を使用しようとしました:
private:
QProcess *process;
//...
QMessageBox myBox(QMessageBox::Information, QString("Info"), QString("Checking connection"), QMessageBox::NoButton, this);
QObject::connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), &myBox, SLOT(close()));
command.append("ping -w 1 172.22.1.1");
process.start(comdand);
myBox.setStandardButtons(0);
myBox.exec();
そして、それは機能していません。myBox が閉じられることはありません。どうしたの?