Hi guys
I am currently learning Qt and now i'm working on address book.I need to know how i can insert name,email and phone Number into TableWidget by using an addItem Dialog.
What i need is this ,after user has added name,email and phoneNumer in the dialog ,when Ok button is clicked the items should be Inserted into tableWidget in mainWindow.
sorry for my english.
Here...
adressbook.cpp
#include <QtGui>
#include "addressbook.h"
#include "additem.h"
#include <QAbstractTableModel>
AddressBook
::AddressBook(QWidget *parent
){
ui.setupUi(this);
int col=0;
for(col = 0; col < 3; col++)
{
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
ui.tableWidget->setItem(0,1, item);
}
connect( ui.actionAdd_Item, SIGNAL(triggered()), this, SLOT(addItem()) );
connect( ui.actionEdit_Item, SIGNAL(triggered()), this, SLOT(editItem()) );
connect( ui.actionDelete_Item, SIGNAL(triggered()), this, SLOT(deleteItem()) );
}
void AddressBook::addItem()
{
AddItem dlg( this );
if( dlg.
exec() == QDialog::Accepted ) {
dlg.name(); //I NEED TO KNOW HOW TO INSERT THIS ITEMS INTO ui.tableWidget
dlg.email(); //I NEED TO KNOW HOW TO INSERT THIS ITEMS INTO ui.tableWidget
dlg.phone(); //I NEED TO KNOW HOW TO INSERT THIS ITEMS INTO ui.tableWidget
}
}
AddressBook::~AddressBook()
{
}
#include <QtGui>
#include "addressbook.h"
#include "additem.h"
#include <QAbstractTableModel>
AddressBook::AddressBook(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
int col=0;
for(col = 0; col < 3; col++)
{
QTableWidgetItem *item = new QTableWidgetItem;
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
ui.tableWidget->setItem(0,1, item);
}
connect( ui.actionAdd_Item, SIGNAL(triggered()), this, SLOT(addItem()) );
connect( ui.actionEdit_Item, SIGNAL(triggered()), this, SLOT(editItem()) );
connect( ui.actionDelete_Item, SIGNAL(triggered()), this, SLOT(deleteItem()) );
}
void AddressBook::addItem()
{
AddItem dlg( this );
if( dlg.exec() == QDialog::Accepted )
{
dlg.name(); //I NEED TO KNOW HOW TO INSERT THIS ITEMS INTO ui.tableWidget
dlg.email(); //I NEED TO KNOW HOW TO INSERT THIS ITEMS INTO ui.tableWidget
dlg.phone(); //I NEED TO KNOW HOW TO INSERT THIS ITEMS INTO ui.tableWidget
}
}
AddressBook::~AddressBook()
{
}
To copy to clipboard, switch view to plain text mode
addressbook.h
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include <QtGui/QMainWindow>
#include "ui_addressbook.h"
{
Q_OBJECT
public:
~AddressBook();
private slots:
void addItem();
// void editItem();
//void deleteItem();
private:
Ui::AddressBook ui;
};
#endif // ADDRESSBOOK_H
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include <QtGui/QMainWindow>
#include "ui_addressbook.h"
class QTableWidget;
class AddressBook : public QMainWindow
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
~AddressBook();
private slots:
void addItem();
// void editItem();
//void deleteItem();
private:
Ui::AddressBook ui;
};
#endif // ADDRESSBOOK_H
To copy to clipboard, switch view to plain text mode
additem.h
#ifndef ADDITEM_H
#define ADDITEM_H
#include <QtGui/QDialog>
#include "ui_additem.h"
{
Q_OBJECT
public:
~AddItem();
private:
Ui::AddItem ui;
};
#endif // ADDITEM_H
#ifndef ADDITEM_H
#define ADDITEM_H
#include <QtGui/QDialog>
#include "ui_additem.h"
class AddItem : public QDialog
{
Q_OBJECT
public:
AddItem(QWidget *parent = 0);
const QString name() const;
const QString email() const;
const QString phone() const;
~AddItem();
private:
Ui::AddItem ui;
};
#endif // ADDITEM_H
To copy to clipboard, switch view to plain text mode
additem.cpp
#include "additem.h"
{
ui.setupUi(this);
// QStrinng name;
// QStrinng email;
// QStrinng phone;
}
const QString AddItem
::name() const {
return ui.Name->text();
}
const QString AddItem
::email() const {
return ui.Email->text();
}
const QString AddItem
::phone() const {
return ui.Phone->text();
}
AddItem::~AddItem()
{
}
#include "additem.h"
AddItem::AddItem(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
// QStrinng name;
// QStrinng email;
// QStrinng phone;
}
const QString AddItem::name() const
{
return ui.Name->text();
}
const QString AddItem::email() const
{
return ui.Email->text();
}
const QString AddItem::phone() const
{
return ui.Phone->text();
}
AddItem::~AddItem()
{
}
To copy to clipboard, switch view to plain text mode
Bookmarks