Hello, thank you for answering me again.
I didn't understand your code perfectly. In fact, i can't see the utility of creating everything on header( i use the header only for declaration)
I will answer your questions :
query5.value(0).toString returns the num_Four from my base
ui is the mainwindow widget
and i will post the hole code here :
fiche_article.cpp :
#include "fiche_article.h"
#include "ui_fiche_article.h"
#include <QtDebug>
fiche_article
::fiche_article(QWidget *parent
) : ui(new Ui::fiche_article)
{
ui->setupUi(this);
model->setQuery("SELECT Nom FROM Projet.dbo.Produit");
ui->comboBox->setModel(model);
query.prepare("SELECT Matricule FROM Projet.dbo.Produit WHERE Nom=:nom");
query.bindValue(":nom", ui->comboBox->currentText());
if (query.exec() && query.next()) {
ui->lineEdit_3->setText(query.value(0).toString());
}
// QObject::connect(ui->comboBox, SIGNAL(currentIndexChanged(int)),ui->lineEdit_3, SLOT(setText(ui->comboBox->currentText())));
query2.prepare("SELECT Nom FROM Projet.dbo.Produit WHERE Nom=:nom");
query2.bindValue(":nom", ui->comboBox->currentText());
if (query2.exec() && query2.next()) {
ui->lineEdit->setText(query2.value(0).toString());
}
query3.prepare("SELECT Type FROM Projet.dbo.Produit WHERE Nom=:nom");
query3.bindValue(":nom", ui->comboBox->currentText());
if (query3.exec() && query3.next()) {
ui->lineEdit_2->setText(query3.value(0).toString());
}
query4.prepare("SELECT Quantité FROM Projet.dbo.Produit WHERE Nom=:nom");
query4.bindValue(":nom", ui->comboBox->currentText());
if (query4.exec() && query4.next()) {
ui->spinBox->setValue(query4.value(0).toInt());
}
model2->setQuery("SELECT DISTINCT N_Four FROM Projet.dbo.Produit");
ui->comboBox_2->setModel(model2);
query5.prepare("SELECT N_Four FROM Projet.dbo.Produit WHERE Nom=:nom");
query5.bindValue(":nom", ui->comboBox->currentText());
if (query5.exec() && query5.next()) {
ui->comboBox_2->setItemText(0,query5.value(0).toString());
}
}
fiche_article::~fiche_article()
{
delete ui;
}
void fiche_article
::on_comboBox_currentIndexChanged(const QString &arg1
) {
query.prepare("SELECT Matricule FROM Projet.dbo.Produit WHERE Nom=:nom");
query.bindValue(":nom", ui->comboBox->currentText());
if (query.exec() && query.next()) {
ui->lineEdit_3->setText(query.value(0).toString());
}
query3.prepare("SELECT Type FROM Projet.dbo.Produit WHERE Nom=:nom");
query3.bindValue(":nom", ui->comboBox->currentText());
if (query3.exec() && query3.next()) {
ui->lineEdit_2->setText(query3.value(0).toString());
}
query4.prepare("SELECT Quantité FROM Projet.dbo.Produit WHERE Nom=:nom");
query4.bindValue(":nom", ui->comboBox->currentText());
if (query4.exec() && query4.next()) {
ui->spinBox->setValue(query4.value(0).toInt());
}
}
#include "fiche_article.h"
#include "ui_fiche_article.h"
#include <QtDebug>
fiche_article::fiche_article(QWidget *parent) :
QDialog(parent),
ui(new Ui::fiche_article)
{
ui->setupUi(this);
this->model = new QSqlQueryModel();
model->setQuery("SELECT Nom FROM Projet.dbo.Produit");
ui->comboBox->setModel(model);
QSqlQuery query;
query.prepare("SELECT Matricule FROM Projet.dbo.Produit WHERE Nom=:nom");
query.bindValue(":nom", ui->comboBox->currentText());
if (query.exec() && query.next()) {
ui->lineEdit_3->setText(query.value(0).toString());
}
// QObject::connect(ui->comboBox, SIGNAL(currentIndexChanged(int)),ui->lineEdit_3, SLOT(setText(ui->comboBox->currentText())));
QSqlQuery query2;
query2.prepare("SELECT Nom FROM Projet.dbo.Produit WHERE Nom=:nom");
query2.bindValue(":nom", ui->comboBox->currentText());
if (query2.exec() && query2.next()) {
ui->lineEdit->setText(query2.value(0).toString());
}
QSqlQuery query3;
query3.prepare("SELECT Type FROM Projet.dbo.Produit WHERE Nom=:nom");
query3.bindValue(":nom", ui->comboBox->currentText());
if (query3.exec() && query3.next()) {
ui->lineEdit_2->setText(query3.value(0).toString());
}
QSqlQuery query4;
query4.prepare("SELECT Quantité FROM Projet.dbo.Produit WHERE Nom=:nom");
query4.bindValue(":nom", ui->comboBox->currentText());
if (query4.exec() && query4.next()) {
ui->spinBox->setValue(query4.value(0).toInt());
}
this->model2 = new QSqlQueryModel();
model2->setQuery("SELECT DISTINCT N_Four FROM Projet.dbo.Produit");
ui->comboBox_2->setModel(model2);
QSqlQuery query5;
query5.prepare("SELECT N_Four FROM Projet.dbo.Produit WHERE Nom=:nom");
query5.bindValue(":nom", ui->comboBox->currentText());
if (query5.exec() && query5.next()) {
ui->comboBox_2->setItemText(0,query5.value(0).toString());
}
}
fiche_article::~fiche_article()
{
delete ui;
}
void fiche_article::on_comboBox_currentIndexChanged(const QString &arg1)
{
QSqlQuery query;
query.prepare("SELECT Matricule FROM Projet.dbo.Produit WHERE Nom=:nom");
query.bindValue(":nom", ui->comboBox->currentText());
if (query.exec() && query.next()) {
ui->lineEdit_3->setText(query.value(0).toString());
}
QSqlQuery query3;
query3.prepare("SELECT Type FROM Projet.dbo.Produit WHERE Nom=:nom");
query3.bindValue(":nom", ui->comboBox->currentText());
if (query3.exec() && query3.next()) {
ui->lineEdit_2->setText(query3.value(0).toString());
}
QSqlQuery query4;
query4.prepare("SELECT Quantité FROM Projet.dbo.Produit WHERE Nom=:nom");
query4.bindValue(":nom", ui->comboBox->currentText());
if (query4.exec() && query4.next()) {
ui->spinBox->setValue(query4.value(0).toInt());
}
}
To copy to clipboard, switch view to plain text mode
fiche_article.h :
#ifndef FICHE_ARTICLE_H
#define FICHE_ARTICLE_H
#include <QDialog>
#include <QtGui>
#include <QtSql>
#include <QtCore>
namespace Ui {
class fiche_article;
}
class fiche_article
: public QDialog{
Q_OBJECT
public:
explicit fiche_article
(QWidget *parent
= 0);
~fiche_article();
private slots:
void on_comboBox_currentIndexChanged
(const QString &arg1
);
private:
Ui::fiche_article *ui;
};
#endif // FICHE_ARTICLE_H
#ifndef FICHE_ARTICLE_H
#define FICHE_ARTICLE_H
#include <QDialog>
#include <QtGui>
#include <QtSql>
#include <QtCore>
namespace Ui {
class fiche_article;
}
class fiche_article : public QDialog
{
Q_OBJECT
public:
explicit fiche_article(QWidget *parent = 0);
~fiche_article();
private slots:
void on_comboBox_currentIndexChanged(const QString &arg1);
private:
Ui::fiche_article *ui;
QSqlDatabase db;
QSqlQuery *qry;
QString *sQuery;
QSqlQueryModel *model;
QSqlQueryModel *model2;
};
#endif // FICHE_ARTICLE_H
To copy to clipboard, switch view to plain text mode
main.cpp :
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
and there are many others pages
Bookmarks