PyQt的應用程序工作正常,但是當我關閉它的Python顯示了這個消息:PyQt的錯誤:沒有這樣的信號的QObject :: dataChanged
"Object::connect: No such signal QObject::dataChanged(QModelIndex,QModelIndex)"
是什麼原因呢?程序中沒有dataChanged
信號。
編輯: 的MWE演示錯誤:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtSql import *
import ui_DBMainWindow
global Mw, Table
Id, Name, Size = range(3)
class TTable():
pass
Table = TTable()
class TMainWindow(QMainWindow, ui_DBMainWindow.Ui_MainWindow):
def __init__(self, parent = None):
global Table
QMainWindow.__init__(self, parent)
self.setupUi(self)
self.showMaximized()
self.mapper = QDataWidgetMapper(self)
self.mapper.setModel(Table.Model) # if this line is commented out, error disappear
def main():
global Mw, Table
QApp = QApplication(sys.argv)
DB = QSqlDatabase.addDatabase("QSQLITE")
DB.setDatabaseName("1.db")
Table.Model = QSqlTableModel()
Table.Model.setTable("MainTable")
Table.Model.select()
Mw = TMainWindow()
QApp.exec_()
if __name__ == "__main__":
main()
編輯2:1.db
是數據庫表MainTable
與3個字段:Id
(自動增量隱藏整數鍵),Name
(字符串),Size
(整數)。它可以是空的,同樣的錯誤。
文件ui_DBMainWindow.py
:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'C:\blizzard\Projects\PyQt\DB4\DBMainWindow.ui'
#
# Created: Fri Mar 26 22:04:00 2010
# by: PyQt4 UI code generator 4.4.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 696)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.TableView = QtGui.QTableView(self.centralwidget)
self.TableView.setGeometry(QtCore.QRect(10, 20, 551, 451))
self.TableView.setObjectName("TableView")
self.btAdd = QtGui.QPushButton(self.centralwidget)
self.btAdd.setGeometry(QtCore.QRect(570, 20, 91, 24))
self.btAdd.setObjectName("btAdd")
self.btDel = QtGui.QPushButton(self.centralwidget)
self.btDel.setGeometry(QtCore.QRect(570, 80, 91, 24))
self.btDel.setObjectName("btDel")
self.btEdit = QtGui.QPushButton(self.centralwidget)
self.btEdit.setGeometry(QtCore.QRect(570, 50, 91, 24))
self.btEdit.setObjectName("btEdit")
self.leQueryError = QtGui.QLineEdit(self.centralwidget)
self.leQueryError.setGeometry(QtCore.QRect(10, 550, 551, 20))
self.leQueryError.setObjectName("leQueryError")
self.btQuery = QtGui.QPushButton(self.centralwidget)
self.btQuery.setGeometry(QtCore.QRect(570, 480, 75, 24))
self.btQuery.setObjectName("btQuery")
self.teQuery = QtGui.QTextEdit(self.centralwidget)
self.teQuery.setGeometry(QtCore.QRect(10, 480, 551, 64))
self.teQuery.setObjectName("teQuery")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 19))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "База данных", None, QtGui.QApplication.UnicodeUTF8))
self.btAdd.setText(QtGui.QApplication.translate("MainWindow", "Добавить", None, QtGui.QApplication.UnicodeUTF8))
self.btDel.setText(QtGui.QApplication.translate("MainWindow", "Удалить", None, QtGui.QApplication.UnicodeUTF8))
self.btEdit.setText(QtGui.QApplication.translate("MainWindow", "Редактировать", None, QtGui.QApplication.UnicodeUTF8))
self.btQuery.setText(QtGui.QApplication.translate("MainWindow", "Запрос", None, QtGui.QApplication.UnicodeUTF8))
請提供完整的示例,此腳本不包含ui_DBMainWindow並引用1.db.它應該是什麼? – 2010-03-28 10:35:19