#include "mywidget.h"
#include "ui_mywidget.h"
#include <QtCore>
#include <QtSql/QSqlDatabase>
MyWidget
::MyWidget(QWidget *parent
) :
{
}
{
m_myListWidget->hide();
createConnection() ;
model->setTable("CityType");
model
->setRelation
(typeIndex,
QSqlRelation("CityType",
"rowid",
"cityName"));
model->select();
addressLabel
= new QLabel(tr
("City:"));
typeLabel
= new QLabel(tr
("&Area:"));
nameLabel
= new QLabel(tr
("&street:"));
// typeComboBox->addItem("Delhi");
// typeComboBox->addItem("Gurgaon");
// typeComboBox->addItem("Noida");
addressLabel->setBuddy(typeComboBox);
typeLabel->setBuddy(typeComboBox2);
nameLabel->setBuddy(nameEdit);
typeComboBox->setModel(relModel);
typeComboBox->setModelColumn(relModel->fieldIndex("cityName"));
// typeComboBox->setModelColumn("cityName") ;
layout->addWidget(addressLabel, 0, 0, 1, 1);
layout->addWidget(typeComboBox, 0, 1, 1, 1);
layout->addWidget(typeLabel, 1, 0, 1, 1);
layout->addWidget(typeComboBox2, 1, 1, 1, 1);
layout->addWidget( nameLabel, 2, 0, 1, 1);
layout->addWidget(nameEdit, 2, 1, 1, 1);
layout->addWidget(nextButton, 3, 1, 1, 1);
setLayout(layout);
}
bool MyWidget::createConnection()
{
//db .setDatabaseName("C:\NokiaQtSDK\project/MyWidget/CabBookingDatabase.Sqlite");
db.setDatabaseName("CabBookingDatabase.Sqlite");
if (!db.open())
{
return false;
}
return true;
}
MyWidget::~MyWidget()
{
}
#include "mywidget.h"
#include "ui_mywidget.h"
#include <QtCore>
#include <QtSql/QSqlDatabase>
MyWidget::MyWidget(QWidget *parent) :
QWidget(parent)
{
m_myListWidget = new QListWidget(this);
new QListWidgetItem(tr("From"), m_myListWidget);
connect( m_myListWidget, SIGNAL(itemClicked(QListWidgetItem *)), SLOT(itemClicked (QListWidgetItem *)));
}
void MyWidget::itemClicked(QListWidgetItem *item)
{
m_myListWidget->hide();
createConnection() ;
model = new QSqlRelationalTableModel(this);
model->setTable("CityType");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setRelation(typeIndex,QSqlRelation("CityType","rowid", "cityName"));
model->select();
addressLabel = new QLabel(tr("City:"));
typeComboBox = new QComboBox();
typeLabel = new QLabel(tr("&Area:"));
typeComboBox2 = new QComboBox();
nameLabel = new QLabel(tr("&street:"));
nameEdit = new QLineEdit();
nextButton = new QPushButton(tr("&Submit"));
// typeComboBox->addItem("Delhi");
// typeComboBox->addItem("Gurgaon");
// typeComboBox->addItem("Noida");
addressLabel->setBuddy(typeComboBox);
typeLabel->setBuddy(typeComboBox2);
nameLabel->setBuddy(nameEdit);
QSqlTableModel *relModel = model->relationModel(typeIndex);
typeComboBox->setModel(relModel);
typeComboBox->setModelColumn(relModel->fieldIndex("cityName"));
// typeComboBox->setModelColumn("cityName") ;
QGridLayout *layout = new QGridLayout();
layout->addWidget(addressLabel, 0, 0, 1, 1);
layout->addWidget(typeComboBox, 0, 1, 1, 1);
layout->addWidget(typeLabel, 1, 0, 1, 1);
layout->addWidget(typeComboBox2, 1, 1, 1, 1);
layout->addWidget( nameLabel, 2, 0, 1, 1);
layout->addWidget(nameEdit, 2, 1, 1, 1);
layout->addWidget(nextButton, 3, 1, 1, 1);
setLayout(layout);
item->~QListWidgetItem();
}
bool MyWidget::createConnection()
{
db = QSqlDatabase::addDatabase("QSQLITE");
//db .setDatabaseName("C:\NokiaQtSDK\project/MyWidget/CabBookingDatabase.Sqlite");
db.setDatabaseName("CabBookingDatabase.Sqlite");
if (!db.open())
{
return false;
}
return true;
}
MyWidget::~MyWidget()
{
}
To copy to clipboard, switch view to plain text mode
///////////.pro///////////
Bookmarks