IP 주소로 ping을 수행하고 있고 ping 작업이 진행 중임을 QMessageBox에 표시하려고합니다. 그 후, 응답이 수신되거나 1 초의 시간 초과가 발생하면 QMessageBox를 닫으려고합니다.ping 명령 응답을 기다리는 중 QMessage
코드 :
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는 초보자입니다 때문에 어쩌면 문제는 다른 곳이다.
편집 :
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();
: @atamanroman으로 신호 무효 QProcess를 사용하여 :: Qt는 참조 말한대로 종료 (INT의 ExitCode를, QProcess :: ExitStatus exitStatus) 신호를, 내가 QProcess를 사용하려고했습니다 제안
그리고 작동하지 않습니다. myBox가 절대로 닫히지 않습니다. 뭐가 문제 야?
메시지 상자 (또는 더 나은 QProgressDialog)는 스택에 로컬로 생성되지 않고 QProcess :: finished() 및 :: error() 슬롯에 연결되는 대신 클래스 멤버 여야합니다. –
QDialog에서 상속받은 done()으로 닫아야합니까? –