列表查找
struct先重载==号
struct Department { int Id; QString Name; QString Telephone; QString Contacts; bool Department::operator==(const Department &rhs) const { return (Id == rhs.Id); } };
用qFind查找:
Department userForFind; userForFind.Id=name.toInt(); QVector<Department>::iterator it = qFind(DepartmentList.begin(), DepartmentList.end(), userForFind); // 查找 if (it != DepartmentList.end()) // 找到了 { ed->dp=*it; }
弹窗
QPushButton *okbtn = new QPushButton(QString::fromLocal8Bit("确定")); QPushButton *cancelbtn = new QPushButton(QString::fromLocal8Bit("取消")); QMessageBox *mymsgbox = new QMessageBox; mymsgbox->setIcon(QMessageBox::Warning); mymsgbox->setWindowTitle(QString::fromLocal8Bit("删除提示")); mymsgbox->setText(QString::fromLocal8Bit("是否确定删除该记录?")); mymsgbox->addButton(okbtn, QMessageBox::AcceptRole); mymsgbox->addButton(cancelbtn, QMessageBox::RejectRole); mymsgbox->show(); mymsgbox->exec();//阻塞等待用户输入 if (mymsgbox->clickedButton()==okbtn)//点击了OK按钮 { //dosomething }
界面事件
界面载入事件
void showEvent(QShowEvent *event);
界面退出不一定触发closeEvent事件,但一定会触发hideEvent事件
void hideEvent(QHideEvent *event);