Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //connect from base
- MainWindow *m= new MainWindow;
- db=QSqlDatabase::addDatabase("QODBC");
- db.setDatabaseName("DRIVER={SQL Server};SERVER="+ui->serverName->text()+";DATABASE="+ui->dbName->text()+";Trusted_Connection=yes;");
- if(db.open()){
- this->close();
- m->showMaximized();
- saveSetting();
- }else{
- QMessageBox::critical(this,"Error","Соединение не установлено!"+db.lastError().text());
- }
- //--------------------------------------------------------
- //MainWindow
- MainWindow::MainWindow()
- : mdiArea(new QMdiArea)
- {
- setCentralWidget(mdiArea);
- createAction();
- createMenu();
- createToolBar();
- setWindowTitle(tr("ПК IT HELPER"));
- setWindowIcon(QPixmap(":/servicesmodificata.png"));
- setUnifiedTitleAndToolBarOnMac(true);
- Navi *nav = new Navi(mdiArea);
- QMdiSubWindow *subWindow2 = mdiArea->addSubWindow(nav);
- subWindow2->setGeometry(0, 0, 428, 600);
- subWindow2->show();
- }
- //из Nav вызываются другие подокна
- //------------------------------------------------------
- //класс потока
- class Zapros : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(QSqlQuery qry READ qry WRITE setQry NOTIFY qryChanged)
- Q_PROPERTY(QString str READ str WRITE setStr NOTIFY strChanged)
- QSqlQuery m_qry;
- QString m_str;
- public:
- explicit Zapros(QObject *parent = nullptr);
- QSqlDatabase db;
- QSqlQuery qry() const;
- QString str() const;
- signals:
- void finished();
- void send(QSqlQuery qry);
- void qryChanged(QSqlQuery qry);
- void strChanged(QString str);
- public slots:
- void run();
- void select();
- void setQry(QSqlQuery qry);
- void setStr(QString str);
- };
- //в срр потока
- void Zapros::select()
- {
- qDebug()<<"в потоке";
- qDebug()<<m_str;
- m_qry.exec(m_str);
- m_qry.next();
- emit send(m_qry);
- emit finished();
- }
- //Клас откуда вызван поток
- Comp::Comp(QMdiArea *md, QWidget *parent) :
- QDialog(parent),
- ui(new Ui::Comp)
- {
- MdiAreaComp = md;
- ui->setupUi(this);
- qryModel=new QSqlQueryModel(this);
- setWindowTitle("Список компьютеров");
- ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(ui->tableView,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(customMenu(QPoint)));
- //------------------------------------------соединеие с потоком----------------------------------------------------------------------------
- connect(&thread_1, &QThread::started, &zap1, &Zapros::run);
- connect(&zap1, &Zapros::finished, &thread_1, &QThread::terminate);
- connect(&zap1,SIGNAL(send(QSqlQuery)),this,SLOT(getQry(QSqlQuery)),Qt::DirectConnection);
- zap1.moveToThread(&thread_1);
- //-----------------------------------------------------------------------------------------------------------------------------------------
- s= "select id, maker, model, name, inv, ser, CPU, cpuZ, RAM, ramZ, HDD, hddZ, OSid, eToken, IP, spisan, blokhost, comment from Comp;";
- select();
- ui->comboBox->clear();
- ui->comboBox->addItem("Инв № содержит",QVariant(0));
- ui->comboBox->addItem("Кол-во ОЗУ",QVariant(1));
- ui->comboBox->addItem("Объём HDD",QVariant(2));
- ui->comboBox->addItem("Операционная система",QVariant(3));
- ui->comboBox->addItem("БлокХост",QVariant(4));
- ui->comboBox->addItem("eToken содержит",QVariant(6));
- ui->comboBox->addItem("Статус списания",QVariant(7));
- }
- void Comp::getQry(QSqlQuery qry)
- {
- // qDebug()<<qry.value(0).toInt();
- qryModel->setQuery(qry);
- ui->tableView->setModel(qryModel);
- ui->tableView->horizontalScrollBar();
- ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
- ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
- qryModel->setHeaderData(1, Qt::Horizontal, "Производитель");
- qryModel->setHeaderData(2, Qt::Horizontal, "Модель");
- qryModel->setHeaderData(3, Qt::Horizontal, "Имя");
- qryModel->setHeaderData(4, Qt::Horizontal, "Инвентарный номер");
- qryModel->setHeaderData(5, Qt::Horizontal, "Серийный номер");
- qryModel->setHeaderData(6, Qt::Horizontal, "Процессор");
- qryModel->setHeaderData(7, Qt::Horizontal, "кол-во Ghz");
- qryModel->setHeaderData(8, Qt::Horizontal, "Оперативная парять");
- qryModel->setHeaderData(9, Qt::Horizontal, "кол-во Gb");
- qryModel->setHeaderData(10, Qt::Horizontal, "Жесткий диск");
- qryModel->setHeaderData(11, Qt::Horizontal, "кол-во GB");
- qryModel->setHeaderData(12, Qt::Horizontal, "ОС");
- qryModel->setHeaderData(13, Qt::Horizontal, "eToken");
- qryModel->setHeaderData(14, Qt::Horizontal, "IP");
- qryModel->setHeaderData(15, Qt::Horizontal, "Списан");
- qryModel->setHeaderData(16, Qt::Horizontal, "БлокХост");
- qryModel->setHeaderData(17, Qt::Horizontal, "Комментарий");
- }
- void Comp::select()
- {
- zap1.setStr(s);
- thread_1.start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement