Add new TreeItemWidget using GUI of different class
Hello,
I want to add QTreeWidgetItem using QPussbutton and QlineEdit of different class. here is my code
mainWindow.h
Code:
#include <QMainWindow>
#include "name.h"
.
.
.
{
Q_OBJECT
public:
private;
Ui::MainWindow *ui;
}
mainWindow.cpp
Code:
#include "mainwindow.h"
.
.
.
{
ui->treeWidget->setColumncount(1);
ui->treeWidget->addTopLevelItem(item);
}
name.h
Code:
#include <QWidget>
#include "mainwindow.h"
.
.
.
{
Q_OBJECT
public:
Qstring getName(void);
private:
void on_Pussbutton_clicked();
UI::Name * ui;
name.cpp
Code:
#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
}
(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..
Re: Add new TreeItemWidget using GUI of different class
Hi, I think you need to write in line 14 of name.h so that the MOC can see which functions are slots.
Ginsengelf
edit: next time, please copy and paste the code, because something like
Code:
MainWindow * mainW; // use poiter of MainWindow class
mainW->addNewItemToTree(item); // add New Item in the fuction of MainWindow
will crash, and we don't know which errors are just "small mistakes" and which are actual code.
Re: Add new TreeItemWidget using GUI of different class
Thank you for your reply..
sorry, for mistakes and I have already written Private Slots: in name.h line number 14 still it doesnt work..
Re: Add new TreeItemWidget using GUI of different class
Quote:
I have already written Private Slots: in name.h
The correct syntax is
not
And like the previous poster said, if you want help solving code problems, you must post your actual code, not something that sort of looks like your code but really isn't. How are we supposed to know what is a coding mistake versus what is a typing mistake?
Where is the connect() statement where you connect the QPushButton::clicked() signal to the on_PussButton_clicked() slot? If you did this in Qt Designer, is your button actually named "PussButton"?