#include "usbdetectdialog.h" #include "ui_usbdetectdialog.h" #include #include #include #include #include #include "LoUIClass/x_uimsgboxok.h" UsbDetectDialog::UsbDetectDialog(QWidget *parent) : LoQDialog(parent), ui(new Ui::UsbDetectDialog) { ui->setupUi(this); ui->lineEditPassword->setEchoMode(QLineEdit::Password); ui->lineEditPassword->setPlaceholderText(tr("Input password")); QFileInfoList list = QDir::drives(); //获取当前系统的盘符 driver_number=list.count(); m_pTimer = new QTimer(this); connect(m_pTimer,SIGNAL(timeout()),this,SLOT(detectDriver())); connect(ui->bnOk, SIGNAL(clicked()), this, SLOT(onAccepted())); m_pTimer->start(3000); detectDriver(); } UsbDetectDialog::~UsbDetectDialog() { delete ui; } void UsbDetectDialog::detectDriver() { QFileInfoList list = QDir::drives(); //获取当前系统的盘符 int temp_number=0; QStringList strTempListUsb; std::vector driver_types; for(int i=0;iremovable_number) { qDebug()<<"驱动器数量: "<listWidgetUsb->count();n++) { QString strB=ui->listWidgetUsb->item(n)->text(); if(strA==strB) { bExist=true; break; } } if(!bExist) ui->listWidgetUsb->addItem(strA); } } else if(temp_number==removable_number) { //qDebug()<<"未插入/移除可移动驱动器!!!"; } else if(temp_numberlistWidgetUsb->count();m++) // { // QString strA=ui->listWidgetUsb->item(m)->text(); // bool iExist=false; // for(int n=0;nlistWidgetUsb->removeItemWidget(ui->listWidgetUsb->item(m)); // m--; // } // } ui->listWidgetUsb->clear(); ui->listWidgetUsb->addItems(strTempListUsb); } removable_number=temp_number; driver_number=list.count(); ui->listWidgetUsb->setProperty("ssType", "usbList"); ui->listWidgetUsb->setProperty("ssName", "usbListName"); if(removable_number==1) { QListWidgetItem *item = ui->listWidgetUsb->item(0); item->setSelected(true); } } void UsbDetectDialog::onAccepted() { // QList * aa= QList aa=ui->listWidgetUsb->selectedItems(); int iSelectCount=aa.count(); if(iSelectCount>0) { for (int i=0;itext(); emit sigAcceptData(strUsbName,ui->lineEditPassword->text()); } } else { if(ui->listWidgetUsb->count()<=0) { X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("No checked USB device"),this,1); pDlg->exec(); return; } else { X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("please select usb device in list"),this,1); pDlg->exec(); return; } } close(); }