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
Qt Code:
  1. #include <QtGui>
  2. #include "addressbook.h"
  3. #include "additem.h"
  4. #include <QAbstractTableModel>
  5. AddressBook::AddressBook(QWidget *parent)
  6. : QMainWindow(parent)
  7. {
  8.  
  9. ui.setupUi(this);
  10. int col=0;
  11. for(col = 0; col < 3; col++)
  12. {
  13. item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
  14. ui.tableWidget->setItem(0,1, item);
  15. }
  16. connect( ui.actionAdd_Item, SIGNAL(triggered()), this, SLOT(addItem()) );
  17. connect( ui.actionEdit_Item, SIGNAL(triggered()), this, SLOT(editItem()) );
  18. connect( ui.actionDelete_Item, SIGNAL(triggered()), this, SLOT(deleteItem()) );
  19. }
  20.  
  21. void AddressBook::addItem()
  22. {
  23.  
  24. AddItem dlg( this );
  25.  
  26.  
  27. if( dlg.exec() == QDialog::Accepted )
  28. {
  29.  
  30. dlg.name(); //I NEED TO KNOW HOW TO INSERT THIS ITEMS INTO ui.tableWidget
  31. dlg.email(); //I NEED TO KNOW HOW TO INSERT THIS ITEMS INTO ui.tableWidget
  32. dlg.phone(); //I NEED TO KNOW HOW TO INSERT THIS ITEMS INTO ui.tableWidget
  33.  
  34.  
  35.  
  36. }
  37. }
  38. AddressBook::~AddressBook()
  39. {
  40.  
  41. }
To copy to clipboard, switch view to plain text mode 



addressbook.h
Qt Code:
  1. #ifndef ADDRESSBOOK_H
  2. #define ADDRESSBOOK_H
  3.  
  4. #include <QtGui/QMainWindow>
  5. #include "ui_addressbook.h"
  6. class AddressBook : public QMainWindow
  7. {
  8. Q_OBJECT
  9.  
  10. public:
  11. AddressBook(QWidget *parent = 0);
  12. ~AddressBook();
  13.  
  14. private slots:
  15.  
  16. void addItem();
  17. // void editItem();
  18. //void deleteItem();
  19. private:
  20. Ui::AddressBook ui;
  21. };
  22.  
  23. #endif // ADDRESSBOOK_H
To copy to clipboard, switch view to plain text mode 


additem.h
Qt Code:
  1. #ifndef ADDITEM_H
  2. #define ADDITEM_H
  3.  
  4. #include <QtGui/QDialog>
  5. #include "ui_additem.h"
  6.  
  7. class AddItem : public QDialog
  8. {
  9. Q_OBJECT
  10.  
  11. public:
  12. AddItem(QWidget *parent = 0);
  13. const QString name() const;
  14. const QString email() const;
  15. const QString phone() const;
  16. ~AddItem();
  17.  
  18. private:
  19. Ui::AddItem ui;
  20. };
  21.  
  22. #endif // ADDITEM_H
To copy to clipboard, switch view to plain text mode 

additem.cpp
Qt Code:
  1. #include "additem.h"
  2.  
  3. AddItem::AddItem(QWidget *parent)
  4. : QDialog(parent)
  5. {
  6. ui.setupUi(this);
  7. // QStrinng name;
  8. // QStrinng email;
  9. // QStrinng phone;
  10. }
  11. const QString AddItem::name() const
  12. {
  13. return ui.Name->text();
  14. }
  15.  
  16. const QString AddItem::email() const
  17. {
  18. return ui.Email->text();
  19. }
  20. const QString AddItem::phone() const
  21. {
  22. return ui.Phone->text();
  23. }
  24. AddItem::~AddItem()
  25. {
  26.  
  27. }
To copy to clipboard, switch view to plain text mode