bonsoir, j'ai travaille avec oracle 11gr2 sous ubuntu , j'ai un projet sur qt creator mais je ne sais pas comment le connecter avec oracle
j'ai dans le fichier
utitled1.pro
mainWindow.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part QT += core gui sql
mainWindow.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include<QtSql> #include<QDebug> #include<QFileInfo> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_pushButton_clicked(); private: Ui::MainWindow *ui; QSqlDatabase db; }; #endif // MAINWINDOW_H
est ce qu'il y a un driver pour télécharger ? Y at-il un problème dans le code ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 #include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QSqlDatabase db = QSqlDatabase::addDatabase("QOCI"); db.setHostName("localhost:8080"); db.setDatabaseName("customdb"); // c'est quoi le nom ? db.setUserName("******"); db.setPassword("*******"); if(!db.open()) ui->label->setText("Failed to open the database"); else ui->label->setAcceptDrops("Connected..."); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QString username,password; username=ui->lineEdit_usernmae->text(); password=ui->lineEdit_password->text(); if(!db.isOpen()){ qDebug()<<"Failed to open the database"; return; } QSqlQuery qry; if(qry.exec("select * from employeeinfo where username='"+username+"' and password='"+password+"'")){ int count=0; while(qry.next()){ count++; } if(count==1) ui->label->setText("usermane and password is correct"); if(count>1) ui->label->setText("Duplicate usermane and password"); if(count<1) ui->label->setText("usermane and password is not correct"); } }
s'il vous plais qui peut m'aider
Partager