Hello,
I want to add QTreeWidgetItem using QPussbutton and QlineEdit of different class. here is my code

mainWindow.h

Qt Code:
  1. #include <QMainWindow>
  2. #include "name.h"
  3. .
  4. .
  5. .
  6. class MainWindow : public QMainWindow
  7. {
  8. Q_OBJECT
  9.  
  10. public:
  11.  
  12. void addNewItemToTree(QTreeWidgetItem *item);
  13.  
  14. private;
  15.  
  16. Ui::MainWindow *ui;
  17.  
  18. }
To copy to clipboard, switch view to plain text mode 

mainWindow.cpp

Qt Code:
  1. #include "mainwindow.h"
  2. .
  3. .
  4. .
  5. void MainWindow::addNewItemToTree(QTreeWidgetItem *item)
  6. {
  7. ui->treeWidget->setColumncount(1);
  8. ui->treeWidget->addTopLevelItem(item);
  9. }
To copy to clipboard, switch view to plain text mode 

name.h
Qt Code:
  1. #include <QWidget>
  2. #include "mainwindow.h"
  3. .
  4. .
  5. .
  6. class Name : public QWidget
  7. {
  8. Q_OBJECT
  9.  
  10. public:
  11.  
  12. Qstring getName(void);
  13.  
  14. private:
  15.  
  16. void on_Pussbutton_clicked();
  17.  
  18. UI::Name * ui;
To copy to clipboard, switch view to plain text mode 

name.cpp

Qt Code:
  1. #include "name.h"
  2. .
  3. .
  4. .
  5. QString Name:: getName (void)
  6. {
  7. return ui->lineEdit->text();
  8. }
  9.  
  10. void Name::on_PussButton_clicked()
  11. {
  12.  
  13. item->setText(0,getName());
  14.  
  15.  
  16. MainWindow * mainW; // use poiter of MainWindow class
  17. mainW->addNewItemToTree(item); // add New Item in the fuction of MainWindow
  18. }
To copy to clipboard, switch view to plain text mode 
(Code hab been typed so plese ignor smalls mistacks)
I am using these code. After clicking pussbutton item is not added in TreeWidget even I am not getting output either neither error.

looking for your guidance or solution..

Thanks..