Hello,
I want to add QTreeWidgetItem using QPussbutton and QlineEdit of different class. here is my code
mainWindow.h
#include <QMainWindow>
#include "name.h"
.
.
.
{
Q_OBJECT
public:
private;
Ui::MainWindow *ui;
}
#include <QMainWindow>
#include "name.h"
.
.
.
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
void addNewItemToTree(QTreeWidgetItem *item);
private;
Ui::MainWindow *ui;
}
To copy to clipboard, switch view to plain text mode
mainWindow.cpp
#include "mainwindow.h"
.
.
.
{
ui->treeWidget->setColumncount(1);
ui->treeWidget->addTopLevelItem(item);
}
#include "mainwindow.h"
.
.
.
void MainWindow::addNewItemToTree(QTreeWidgetItem *item)
{
ui->treeWidget->setColumncount(1);
ui->treeWidget->addTopLevelItem(item);
}
To copy to clipboard, switch view to plain text mode
name.h
#include <QWidget>
#include "mainwindow.h"
.
.
.
{
Q_OBJECT
public:
Qstring getName(void);
private:
void on_Pussbutton_clicked();
UI::Name * ui;
#include <QWidget>
#include "mainwindow.h"
.
.
.
class Name : public QWidget
{
Q_OBJECT
public:
Qstring getName(void);
private:
void on_Pussbutton_clicked();
UI::Name * ui;
To copy to clipboard, switch view to plain text mode
name.cpp
#include "name.h"
.
.
.
{
return ui->lineEdit->text();
}
void Name::on_PussButton_clicked()
{
item->setText(0,getName());
MainWindow * mainW; // use poiter of MainWindow class
mainW->addNewItemToTree(item); // add New Item in the fuction of MainWindow
}
#include "name.h"
.
.
.
QString Name:: getName (void)
{
return ui->lineEdit->text();
}
void Name::on_PussButton_clicked()
{
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0,getName());
MainWindow * mainW; // use poiter of MainWindow class
mainW->addNewItemToTree(item); // add New Item in the fuction of MainWindow
}
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..
Bookmarks