使用QFileDialog非常好用。
void HandleThreadAndTest::sBrowseFile()
{
QString path = QFileDialog::getOpenFileName(this, tr("Open .pacp"), ".", tr("Pcap Files(*.pcap *.pcapng)"));
if (path.length() == 0)
{
QMessageBox::information(NULL, tr("Path"), tr("You didn't select any files."));
}
else
{
ui.sendFileName->setText(path);
}
}