Я выполняю команду ping на IP-адрес и хочу показать в QMessageBox, что происходит операция ping. После этого, если получен ответ или произошел тайм-аут в одну секунду, я хочу закрыть 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, возможно, проблема в другом месте.
EDIT:
Как подсказал @atamanroman, я пытался использовать QProcess, используя void сигнала QProcess :: finish (int exitCode, QProcess :: ExitStatus exitStatus) [signal], как сказано в ссылке Qt:
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 никогда не закрывается. Что не так?