QObject::~QObject(){ .... if (d->parent) // remove it from parent object d->setParent_helper(0); .....}
C++ (Qt)#ifndef ROSZDRAV_H#define ROSZDRAV_H #include <QtGui/QDialog>#include <QSqlQueryModel>#include <QString>#include <QMessageBox>#include <QSqlError>#include <QSqlDatabase>#include <QVariant>#include <QAction>#include <QMenu> #include "ls.h"#include "ui_roszdrav.h" class LS;class Roszdrav : public QDialog{ Q_OBJECT public: Roszdrav(QWidget *parent,QString text); ~Roszdrav(); closeEvent(QCloseEvent *event) QSqlQueryModel *ls; LS *l;private: Ui::RoszdravClass ui;private slots: void add();}; #endif // ROSZDRAV_H
C++ (Qt)Roszdrav::Roszdrav(QWidget *parent,QString text) :QDialog(parent){ ui.setupUi(this); createActions(); this->setWindowTitle("ЛС из Росздрава"); ls=new QSqlQueryModel(this); str="SELECT Roszdrav.id,Roszdrav.mnn,Roszdrav.rf_mnn_terr_prog, " "Roszdrav.name_med,Roszdrav.Form_vipuska,Roszdrav.producer, " "Roszdrav.kv_all,Roszdrav.price,Roszdrav.status " "FROM Roszdrav " "WHERE rf_mnn_terr_prog is not NULL and name_med like '"+text+"%' " "ORDER BY Roszdrav.name_med,Roszdrav.Form_vipuska,Roszdrav.kv_all,Roszdrav.price"; ls->setQuery(str); namecolumns(); ui.tableLS->setModel(ls); connect(ui.add,SIGNAL(clicked()),this,SLOT(add())); this->setFixedSize(899,300);}void Roszdrav::closeEvent(QCloseEvent *event){ delete ls; if(l!=NULL) delete l; event->accept();}void Roszdrav::add(){ l=new LS(this); if(l->exec()==QDialog::Accepted){ ls->setQuery(str); while (ls->canFetchMore()) ls->fetchMore(); sizecolumns(); QModelIndexList indexList = ls->match(ls->index(0,0),Qt::DisplayRole,l->roszdid,1, Qt::MatchExactly); QModelIndex index=indexList.first(); int ind =index.row(); ui.tableLS->selectRow(ind); } delete l;}