Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Warning shown in QT. Should I be worried about it? Or can I choose to ignore it?
Forum Updated to NodeBB v4.3 + New Features

Warning shown in QT. Should I be worried about it? Or can I choose to ignore it?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 174 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    burrito1111
    wrote on last edited by
    #1

    I have added a database connection in two of my windows in QT.

    login.cpp

    mydb = QSqlDatabase::addDatabase("QSQLITE");
        mydb.setDatabaseName("C:/Users/burr1to/Desktop/Kaizen/Kaizen/testdb.db");
        if (!mydb.open()){
            qDebug()<<"Db problem";
        } else {
            qDebug()<< "Success";
        }
    
        QString username = ui->username->text();
        QString password = ui->password->text();
        QSqlQuery qry;
    
        if(qry.exec("select * from user where username = '"+username+"' and password = '"+password+"'")){
            int count=0;
            while(qry.next()){
                count++;
            }
            if (count==1){
                qDebug()<< "Successful login";
                qry.clear();
                mydb.close();
                hide();
                p.show();
    
            }
            if (count<1){
                qDebug()<< "NOT Successful login";
                qry.clear();
                mydb.close();
            }
        }
    

    planner.cpp

        db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("C:/Users/burr1to/Desktop/Kaizen/Kaizen/testdb.db");
        if (!db.open()){
            qDebug()<< "Failed";
        } else {
            qDebug()<< "Success";
    
        }
        if (!db.open()){
            return;
        }
        QString what = ui->addPlan->text();
    
        QSqlQuery q;
        if (what == ""){
            qDebug()<< "MT";
        }
        else{
            q.prepare("insert into plan(plandet) values (:plan)");
            q.bindValue(":plan",what);
            if (q.exec()){
                qDebug()<< "Ok";
            }}
    
    
    
        ui->addPlan->clear();
    

    So the 'planner' page opens after the 'login' page, and even though I have closed the database in login.cpp, a warning is shown in console.

    QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
    QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.

    Should I be worried about this? And what should I do to not get this error? Is the error happening because I used the same DB connection twice?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You should worry about it.
      Don't open the database more than once and then use QSqlDatabase::database() to retrieve the db connection (if you really need it)

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved