К слову - я полный нуб. Имеется класс с некоторыми данными, которые отображаются в главном окне в виджете Так же в главном окне реализован поиск по объектам данного класса следующим образом: | Код | void MainWindow::searchButtonClicked() { dataListOut = new List(this); QString famwor = Edit1->text(); int kol = 0; QModelIndex index; Hospital pacient; //создаем объект класса, по которому ищем view1->reset(); int col = 0; for(int r=0; r<dataListOut->rowCount();r++) { index = dataListOut->index(r,col,QModelIndex()); dataListOut->delPacient(index); } int column=0; for(int row=0; row<dataList->rowCount(); row++) { index = dataList->index(row,column,QModelIndex()); pacient = dataList->getPacient(index); if (pacient.getfam() == famwor) { kol++; dataListOut->addPacient(pacient); } } view1->setModel(dataListOut); view1->resizeColumnsToContents(); view1->resizeRowsToContents(); QString str; str.setNum(kol); Label2->setText(str); }
|
Тоесть мы вводим фамилию, и если pacient.getfam==famwor, мы отображаем его в QTableView *view2. Нужно реализовать точно такой же поиск, но не в главном окне, а в новом, в этом вся проблема Для этого создал новый класс | Код | #ifndef SEARCHFAM_H #define SEARCHFAM_H #include <QDialog> #include <QLineEdit> #include <QPushButton> #include <QDialogButtonBox> #include <list.h> #include <QTableView> #include <QLabel> class Searchfam:public QDialog { void createWidgets(); void placeWidgets(); void connectSlots(); QDialogButtonBox *buttons; QLineEdit *Edit2; List *dataList; QTableView *view1; List *dataListOut; QLabel *Label1, *Label2; public: Searchfam(); public slots: void accept(); }; #endif // SEARCHFAM_H
|
и cpp'шный | Код | #include "searchfam.h" #include "list.h" #include "editdialog.h" #include <mainwindow.h> #include <QFormLayout> #include <QMessageBox> Searchfam::Searchfam() { createWidgets(); connectSlots(); placeWidgets(); setWindowTitle("Найти по фамилии..."); } void Searchfam::createWidgets() { Edit2 = new QLineEdit; buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); } void Searchfam::placeWidgets() { QFormLayout *mainLayout = new QFormLayout; mainLayout->setHorizontalSpacing(20); mainLayout->addRow("Задайте фамилию", Edit2); mainLayout->addRow(buttons); setLayout(mainLayout); } void Searchfam::connectSlots() { connect(buttons, SIGNAL(accepted()), this, SLOT(accept())); connect(buttons, SIGNAL(rejected()), this, SLOT(reject())); } void Searchfam::accept() { dataListOut = new List(this); QString famwor = Edit2->text(); int kol = 0; QModelIndex index; Hospital pacient; view1->reset(); int col = 0; for(int r=0; r<dataListOut->rowCount();r++) { index = dataListOut->index(r,col,QModelIndex()); dataListOut->delPacient(index); } int column=0; for(int row=0; row<dataList->rowCount(); row++) { index = dataList->index(row,column,QModelIndex()); pacient = dataList->getPacient(index); if (pacient.getfam() == famwor) { kol++; dataListOut->addPacient(pacient); } } view1->setModel(dataListOut); view1->resizeColumnsToContents(); view1->resizeRowsToContents(); QString str; str.setNum(kol); Label2->setText(str); QDialog::accept(); }
|
Что нужно написать в слоте accept(), чтобы поиск осуществлялся и результат выводился с главном окне в view1?
|