Results 1 to 1 of 1

Thread: Closing Connection to Sqlite

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2017
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Closing Connection to Sqlite

    i always have this kind of error. i saw that someone already asked for but my code it's different.
    the connexion is right but whent i execute a query i receive this message and can't execute query again
    the error:

    QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
    Connexion reussie.

    that my code. header

    QSqlDatabase mydb;

    bool open_data()
    {
    mydb = QSqlDatabase::addDatabase("QSQLITE");
    mydb.setDatabaseName("C:/SQlite/SQLiteManager-1.2.4/Class1a.sqlite");

    if (!mydb.open())
    {
    qDebug()<<("Echec de la connexion")<<mydb.lastError().text();
    return false;
    }
    else
    {
    qDebug()<<("Connexion reussie");
    return true;
    }

    }//ending function

    void close_data()
    {
    mydb.close();
    mydb.removeDatabase(QSqlDatabase::defaultConnectio n);
    //

    } // ending function

    /////////////////

    // file.cpp

    void Databse:: message()

    {
    if (!open_data())
    {
    qWarning()<<"Echec de la connexion"<<mydb.lastError().text();
    }


    QSqlQueryModel * modal = new QSqlQueryModel;
    open_data();
    QSqlQuery query;
    query.prepare("SELECT Name,Lastname,Balance FROM fgrade order by Name,Lastname");

    if(!query.exec())
    {

    QMessageBox::critical(this,tr("error::"),query.las tError().text());

    }
    else
    {
    modal->setQuery(query);
    tablev->setModel(modal);
    close_data();
    QMessageBox::warning(this,"Sauvegarde","donnees triees normalement");

    }

    }// ending function
    i'am waiting for your assistant. please!
    Last edited by Dydy02; 12th October 2017 at 03:40.

Similar Threads

  1. Replies: 1
    Last Post: 25th March 2012, 23:15
  2. connection to sqlite database using qt4
    By elimelick in forum Newbie
    Replies: 0
    Last Post: 25th July 2010, 15:53
  3. SQLite connection and encoding
    By mhbeyle in forum Qt Programming
    Replies: 2
    Last Post: 3rd December 2009, 16:25
  4. Closing correctly sqlite connection?
    By 0xl33t in forum Newbie
    Replies: 1
    Last Post: 9th August 2009, 14:22
  5. QT - SQLite Connection
    By sabeesh in forum Qt Programming
    Replies: 14
    Last Post: 3rd June 2009, 14:58

Tags for this Thread

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.