#ifndef PIECEINSERT_H
#define PIECEINSERT_H
#include <QDialog>
{
Q_OBJECT
public:
private slots:
void insertRecordSlot();
private:
};
#endif
#ifndef PIECEINSERT_H
#define PIECEINSERT_H
#include <QDialog>
class QLabel;
class QLineEdit;
class QComboBox;
class QSqlTableModel;
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
private slots:
void insertRecordSlot();
private:
QLabel *itemLabel;
QSqlTableModel *model;
QLabel *pieceNameLabel;
QLineEdit *pieceNameLineEdit;
QLabel *statusLabel;
QComboBox *statusComboBox;
QPushButton *closeButton;
QPushButton *submitButton;
};
#endif
To copy to clipboard, switch view to plain text mode
pieceInsert.cpp
#include <QApplication>
...
#include "pieceInsert.h"
{
// Window Title
window->setWindowTitle("NNBS Piece Entry");
window->setFixedSize(450, 270);
// Piece Entry Section
pieceNameLabel
= new QLabel();
pieceNameLabel->setText("Piece Name");
statusLabel->setText("Status");
statusComboBox->addItem("In Progress");
statusComboBox->addItem("Dormant");
statusComboBox->addItem("Complete");
h2BoxLayout->addWidget(pieceNameLabel);
h2BoxLayout->addWidget(pieceNameLineEdit);
h2BoxLayout->addWidget(statusLabel);
h2BoxLayout->addWidget(statusComboBox);
// **** Start Create Buttons ****//
// Close Button Layout
QObject::connect(closeButton,
SIGNAL(clicked
()),
qApp,
SLOT(quit
()));
// Submit Button
QObject::connect(submitButton,
SIGNAL(clicked
()),
qApp,
SLOT(insertRecordSlot
()));
// Create Buttons Layout
hBoxLayout->addItem(spacerItem);
hBoxLayout->addWidget(submitButton);
hBoxLayout->addWidget(closeButton);
// **** End Buttons **** //
// Entire Layout
vBoxLayout->addLayout(h2BoxLayout);
vBoxLayout->addLayout(hBoxLayout);
window->setLayout(vBoxLayout);
window->show();
}
void Dialog::insertRecordSlot()
{
// SQL Insert Record
rec.setValue("piece_name", pieceNameLineEdit->text());
rec.setValue("status", statusComboBox->currentText());
model->setTable("main");
model->insertRecord(-1, rec);
}
#include <QApplication>
...
#include "pieceInsert.h"
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
// Window Title
QWidget *window = new QWidget;
window->setWindowTitle("NNBS Piece Entry");
window->setFixedSize(450, 270);
// Piece Entry Section
pieceNameLabel = new QLabel();
pieceNameLabel->setText("Piece Name");
pieceNameLineEdit = new QLineEdit();
statusLabel = new QLabel();
statusLabel->setText("Status");
statusComboBox = new QComboBox();
statusComboBox->addItem("In Progress");
statusComboBox->addItem("Dormant");
statusComboBox->addItem("Complete");
QHBoxLayout *h2BoxLayout = new QHBoxLayout;
h2BoxLayout->addWidget(pieceNameLabel);
h2BoxLayout->addWidget(pieceNameLineEdit);
h2BoxLayout->addWidget(statusLabel);
h2BoxLayout->addWidget(statusComboBox);
// **** Start Create Buttons ****//
// Close Button Layout
closeButton = new QPushButton("Close");
QObject::connect(closeButton, SIGNAL(clicked()), qApp, SLOT(quit()));
// Submit Button
submitButton = new QPushButton("Submit");
QObject::connect(submitButton, SIGNAL(clicked()), qApp, SLOT(insertRecordSlot()));
// Create Buttons Layout
QHBoxLayout *hBoxLayout = new QHBoxLayout;
QSpacerItem *spacerItem = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hBoxLayout->addItem(spacerItem);
hBoxLayout->addWidget(submitButton);
hBoxLayout->addWidget(closeButton);
// **** End Buttons **** //
// Entire Layout
QVBoxLayout *vBoxLayout = new QVBoxLayout;
vBoxLayout->addLayout(h2BoxLayout);
vBoxLayout->addLayout(hBoxLayout);
window->setLayout(vBoxLayout);
window->show();
}
void Dialog::insertRecordSlot()
{
// SQL Insert Record
QSqlRecord rec;
rec.append(QSqlField("piece_name", QVariant::String));
rec.append(QSqlField("status", QVariant::String));
rec.setValue("piece_name", pieceNameLineEdit->text());
rec.setValue("status", statusComboBox->currentText());
model = new QSqlTableModel;
model->setTable("main");
model->insertRecord(-1, rec);
}
To copy to clipboard, switch view to plain text mode
Any suggestions?
Bookmarks