PDA

View Full Version : QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connectio



antilopeeh
18th November 2015, 22:59
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

jefftee
19th November 2015, 04:19
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!

antilopeeh
19th November 2015, 19:45
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.

jefftee
19th November 2015, 19:50
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.