Results 1 to 2 of 2

Thread: error while executing qt application

  1. #1
    Join Date
    Mar 2012
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default error while executing qt application

    hi,
    I have a qt interface with 2 text box N_departement and department and a button add
    the program is to add these two text boxes in the department table in a postgresql database
    but I get the following error I do not know why
    when I click the Add button
    QSqlQuery:repare: database not open
    "QODBCResult::exec: No statement handle available" Error: ""
    this is what i wrote:
    nomenclature.h
    <code type="cpp">
    #ifndef NOMENCLATURE_H
    #define NOMENCLATURE_H

    #include <QMainWindow>
    #include <QtSql>
    namespace Ui {
    class nomenclature;
    }

    class nomenclature : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit nomenclature(QWidget *parent = 0);
    ~nomenclature();
    void connexion_based();

    private:
    Ui::nomenclature *ui;
    QSqlDatabase db;

    private slots:
    void on_Ajouter_clicked();

    };

    #endif // NOMENCLATURE_H
    </code>
    nomenclature.cpp
    <code type="cpp">
    #include "nomenclature.h"
    #include "ui_nomenclature.h"
    #include <QtSql>
    nomenclature::nomenclature(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::nomenclature)
    { this->connexion_based();
    ui->setupUi(this);
    QObject::connect(ui->Ajouter,SIGNAL(clicked()),this,SLOT(on_Ajouter_cl icked()));
    }

    nomenclature::~nomenclature()
    {
    delete ui;
    }
    void nomenclature::connexion_based()
    {
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setHostName("localhost");
    db.setUserName("postgres");
    db.setPassword("khadija");
    db.setDatabaseName("d");
    db.open();
    if(db.open())
    {
    qDebug()<< "opened" ;
    db.close();
    }
    else
    {
    qDebug() << "ERROR" << db.lastError().text();
    }

    }


    void nomenclature:n_Ajouter_clicked()
    {
    QSqlQuery sql(db);
    sql.prepare("INSERT INTO departement VALUES (:n_dep, :libellé_dep);");
    sql.bindValue(":n_dep",ui->n_departement->text().toInt());
    sql.bindValue(":libellé_dep",ui->intitule_departement->text());
    sql.exec();
    }
    </code>
    main.cpp
    <code type="cpp">
    #include <QtGui/QApplication>
    #include "nomenclature.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    nomenclature w;
    w.show();

    return a.exec();
    }
    </code>
    can you help me please
    ajouter une réponsethank you

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: error while executing qt application

    You most likely do not have the ODBC (the one you are trying to use) or PostgreSQL (QPSQL, the one you probably should use) Qt plugins built and installed.

    BTW: Your code tags are wrong.

Similar Threads

  1. Got a weird error while executing my programs
    By poudigne in forum Newbie
    Replies: 1
    Last Post: 26th November 2011, 06:37
  2. Runtime error while executing a project
    By bajoelkid12 in forum Qt Programming
    Replies: 4
    Last Post: 10th June 2011, 04:45
  3. Error while executing the exe release file
    By harmodrew in forum Newbie
    Replies: 7
    Last Post: 21st September 2010, 10:21
  4. Replies: 2
    Last Post: 11th August 2010, 10:13
  5. Error while executing a application - Gtk WARNING
    By augusbas in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2010, 12:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.