Results 1 to 4 of 4

Thread: QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connectio

  1. #1
    Join Date
    Nov 2015
    Posts
    2
    Qt products
    Platforms
    Windows

    Question QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connectio

    Hi guys, i have this problem in my program and I dont know how to solve this, if anybody can help me, i would be grateful.
    Ps: Sry for the bad english.

    This is a piece of my program

    from PyQt4 import QtGui, QtSql
    from PyQt4.QtCore import pyqtSlot
    from PyQt4.QtGui import QWidget
    from Ui_Login import Ui_Form
    from Ui_Main import Ui_Form2
    from Ui_Contrato import Ui_Form3


    @pyqtSlot()
    def on_pushButton_5_clicked(self):
    self.CPF = self.lineEdit.text()
    db = QtSql.QSqlDatabase.addDatabase ('QSQLITE')
    db.setDatabaseName ('CARALHO.db')
    if not db.open():
    print ('erro')
    q = QtSql.QSqlQuery()
    q.exec_("select nome from MERDA where CPF=('"+self.lineEdit.text()+"')")
    if q.next():
    self.nome=q.value(0)
    self.label_8.setText(self.nome)
    self.invalido= 0

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_conne

    I don't know Python/Qt, but do you perhaps have a separate QSqlDatabase.addDatabase call somewhere else in your code? Since you don't specify a connection name, the connection becomes the default connection and if you have another QSqlDatabase::addDatabase somewhere else in your code that does not specify a connection name, that is likely the source of the duplicate connection name.

    Either specify the connection name for both or one of those and it should resolve your problem.

    Good luck!
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    Nov 2015
    Posts
    2
    Qt products
    Platforms
    Windows

    Default Re: QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_conne

    Quote Originally Posted by jefftee View Post
    I don't know Python/Qt, but do you perhaps have a separate QSqlDatabase.addDatabase call somewhere else in your code? Since you don't specify a connection name, the connection becomes the default connection and if you have another QSqlDatabase::addDatabase somewhere else in your code that does not specify a connection name, that is likely the source of the duplicate connection name.

    Either specify the connection name for both or one of those and it should resolve your problem.

    Good luck!
    No, I only have this QSqlDatabase.addDatabase call in my enterily code =\.
    I used another DB before, but i deleted all the lines of the code which corresponded to it.
    Thx you for try to help me.

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_conne

    Does it work the first time and get the duplicate connection for the subsequent times your code gets executed?

    I don't see where your db variable is declared in your code, but it seems odd that you would create a new db connection each time your slot is fired. If you have initialization code elsewhere, add your db connection there, set the db filename there, then perform your query in the slot code.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. error while execution duplicate connection name
    By khadija123 in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2012, 14:59
  2. QSqlDatabasePrivate - warning
    By Tomasz in forum Newbie
    Replies: 1
    Last Post: 11th August 2010, 23:34
  3. Replies: 0
    Last Post: 14th July 2010, 13:40
  4. Replies: 3
    Last Post: 22nd June 2006, 16:27
  5. Replies: 10
    Last Post: 6th March 2006, 16:08

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.