2011-05-30 139 views
0

我已经在Qt Designer中创建了一个用户界面,我现在想要显示这些数据。我想要使用多继承方法。这里是用户界面的代码。Qt QTableView多继承方法

/******************************************************************************** 
** Form generated from reading UI file 'prototypejI3444.ui' 
** 
** Created: Mon May 30 10:04:01 2011 
**  by: Qt User Interface Compiler version 4.7.0 
** 
** WARNING! All changes made in this file will be lost when recompiling UI file! 
********************************************************************************/ 

#ifndef PROTOTYPEJI3444_H 
#define PROTOTYPEJI3444_H 

#include <QtCore/QVariant> 
#include <QtGui/QAction> 
#include <QtGui/QApplication> 
#include <QtGui/QButtonGroup> 
#include <QtGui/QGridLayout> 
#include <QtGui/QHeaderView> 
#include <QtGui/QLabel> 
#include <QtGui/QLineEdit> 
#include <QtGui/QMainWindow> 
#include <QtGui/QMenuBar> 
#include <QtGui/QPushButton> 
#include <QtGui/QStatusBar> 
#include <QtGui/QTableView> 
#include <QtGui/QVBoxLayout> 
#include <QtGui/QWidget> 

QT_BEGIN_NAMESPACE 

class Ui_MainWindow 
{ 
public: 
    QWidget *centralwidget; 
    QGridLayout *gridLayout; 
    QVBoxLayout *verticalLayout_2; 
    QLabel *label; 
    QVBoxLayout *verticalLayout_3; 
    QLineEdit *lineEdit; 
    QVBoxLayout *verticalLayout_4; 
    QLabel *label_2; 
    QVBoxLayout *verticalLayout_5; 
    QLineEdit *lineEdit_2; 
    QVBoxLayout *verticalLayout_6; 
    QLabel *label_3; 
    QVBoxLayout *verticalLayout_7; 
    QLineEdit *lineEdit_3; 
    QTableView *tableView; 
    QPushButton *pushButton_2; 
    QPushButton *pushButton_3; 
    QPushButton *pushButton_4; 
    QPushButton *pushButton_5; 
    QPushButton *pushButton_6; 
    QPushButton *pushButton; 
    QMenuBar *menubar; 
    QStatusBar *statusbar; 

    void setupUi(QMainWindow *MainWindow) 
    { 
     if (MainWindow->objectName().isEmpty()) 
      MainWindow->setObjectName(QString::fromUtf8("MainWindow")); 
     MainWindow->resize(800, 600); 
     centralwidget = new QWidget(MainWindow); 
     centralwidget->setObjectName(QString::fromUtf8("centralwidget")); 
     gridLayout = new QGridLayout(centralwidget); 
     gridLayout->setObjectName(QString::fromUtf8("gridLayout")); 
     verticalLayout_2 = new QVBoxLayout(); 
     verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2")); 
     label = new QLabel(centralwidget); 
     label->setObjectName(QString::fromUtf8("label")); 

     verticalLayout_2->addWidget(label); 


     gridLayout->addLayout(verticalLayout_2, 1, 0, 1, 1); 

     verticalLayout_3 = new QVBoxLayout(); 
     verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3")); 
     lineEdit = new QLineEdit(centralwidget); 
     lineEdit->setObjectName(QString::fromUtf8("lineEdit")); 

     verticalLayout_3->addWidget(lineEdit); 


     gridLayout->addLayout(verticalLayout_3, 1, 1, 1, 1); 

     verticalLayout_4 = new QVBoxLayout(); 
     verticalLayout_4->setObjectName(QString::fromUtf8("verticalLayout_4")); 
     label_2 = new QLabel(centralwidget); 
     label_2->setObjectName(QString::fromUtf8("label_2")); 

     verticalLayout_4->addWidget(label_2); 


     gridLayout->addLayout(verticalLayout_4, 2, 0, 1, 1); 

     verticalLayout_5 = new QVBoxLayout(); 
     verticalLayout_5->setObjectName(QString::fromUtf8("verticalLayout_5")); 
     lineEdit_2 = new QLineEdit(centralwidget); 
     lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2")); 

     verticalLayout_5->addWidget(lineEdit_2); 


     gridLayout->addLayout(verticalLayout_5, 2, 1, 1, 1); 

     verticalLayout_6 = new QVBoxLayout(); 
     verticalLayout_6->setObjectName(QString::fromUtf8("verticalLayout_6")); 
     label_3 = new QLabel(centralwidget); 
     label_3->setObjectName(QString::fromUtf8("label_3")); 

     verticalLayout_6->addWidget(label_3); 


     gridLayout->addLayout(verticalLayout_6, 3, 0, 1, 1); 

     verticalLayout_7 = new QVBoxLayout(); 
     verticalLayout_7->setObjectName(QString::fromUtf8("verticalLayout_7")); 
     lineEdit_3 = new QLineEdit(centralwidget); 
     lineEdit_3->setObjectName(QString::fromUtf8("lineEdit_3")); 

     verticalLayout_7->addWidget(lineEdit_3); 


     gridLayout->addLayout(verticalLayout_7, 3, 1, 1, 1); 

     tableView = new QTableView(centralwidget); 
     tableView->setObjectName(QString::fromUtf8("tableView")); 

     gridLayout->addWidget(tableView, 0, 0, 1, 2); 

     pushButton_2 = new QPushButton(centralwidget); 
     pushButton_2->setObjectName(QString::fromUtf8("pushButton_2")); 

     gridLayout->addWidget(pushButton_2, 2, 2, 1, 1); 

     pushButton_3 = new QPushButton(centralwidget); 
     pushButton_3->setObjectName(QString::fromUtf8("pushButton_3")); 

     gridLayout->addWidget(pushButton_3, 3, 2, 1, 1); 

     pushButton_4 = new QPushButton(centralwidget); 
     pushButton_4->setObjectName(QString::fromUtf8("pushButton_4")); 

     gridLayout->addWidget(pushButton_4, 1, 3, 1, 1); 

     pushButton_5 = new QPushButton(centralwidget); 
     pushButton_5->setObjectName(QString::fromUtf8("pushButton_5")); 

     gridLayout->addWidget(pushButton_5, 2, 3, 1, 1); 

     pushButton_6 = new QPushButton(centralwidget); 
     pushButton_6->setObjectName(QString::fromUtf8("pushButton_6")); 

     gridLayout->addWidget(pushButton_6, 3, 3, 1, 1); 

     pushButton = new QPushButton(centralwidget); 
     pushButton->setObjectName(QString::fromUtf8("pushButton")); 

     gridLayout->addWidget(pushButton, 1, 2, 1, 1); 

     MainWindow->setCentralWidget(centralwidget); 
     tableView->raise(); 
     pushButton_2->raise(); 
     pushButton_3->raise(); 
     pushButton_4->raise(); 
     pushButton_5->raise(); 
     pushButton_6->raise(); 
     pushButton->raise(); 
     menubar = new QMenuBar(MainWindow); 
     menubar->setObjectName(QString::fromUtf8("menubar")); 
     menubar->setGeometry(QRect(0, 0, 800, 18)); 
     MainWindow->setMenuBar(menubar); 
     statusbar = new QStatusBar(MainWindow); 
     statusbar->setObjectName(QString::fromUtf8("statusbar")); 
     MainWindow->setStatusBar(statusbar); 

     retranslateUi(MainWindow); 

     QMetaObject::connectSlotsByName(MainWindow); 
    } // setupUi 

    void retranslateUi(QMainWindow *MainWindow) 
    { 
     MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8)); 
     label->setText(QApplication::translate("MainWindow", "FirstName:", 0, QApplication::UnicodeUTF8)); 
     label_2->setText(QApplication::translate("MainWindow", "SecondName:", 0, QApplication::UnicodeUTF8)); 
     label_3->setText(QApplication::translate("MainWindow", "City:", 0, QApplication::UnicodeUTF8)); 
     pushButton_2->setText(QApplication::translate("MainWindow", "New", 0, QApplication::UnicodeUTF8)); 
     pushButton_3->setText(QApplication::translate("MainWindow", "Delete", 0, QApplication::UnicodeUTF8)); 
     pushButton_4->setText(QApplication::translate("MainWindow", "Next", 0, QApplication::UnicodeUTF8)); 
     pushButton_5->setText(QApplication::translate("MainWindow", "Previous", 0, QApplication::UnicodeUTF8)); 
     pushButton_6->setText(QApplication::translate("MainWindow", "First", 0, QApplication::UnicodeUTF8)); 
     pushButton->setText(QApplication::translate("MainWindow", "Save", 0, QApplication::UnicodeUTF8)); 
    } // retranslateUi 

}; 

namespace Ui { 
    class MainWindow: public Ui_MainWindow {}; 
} // namespace Ui 

QT_END_NAMESPACE 

#endif // PROTOTYPEJI3444_H 

在多重继承方法有.h文件和其相应的.cpp.I希望有人指导我在哪里做出SQLite数据库连接(无论其在.cpp文件或。 h文件)以及如何与我显示的UI文件进行通信以显示Qtableview上的数据库中的数据。

谢谢。

回答

0

您实例化QSqlTableModel,使用setModel将其与视图关联,并将适当的表属性初始化为模型。在init中完成所有操作。

+0

感谢您的回复,但我希望有一个小代码来显示哪里去了哪里。 – Gandalf 2011-05-30 10:46:29