How to add Treewidget Items when clicking on PushButton
HI All,
i getting a problem, when iam clicking on pushbutton(OK) the TreeWidgetItems are not adding not only that ,the mainwindow is also closing when iam clicking on push button(OK).plz go throught the below code and let me know what the mistake i had done and how to solve this issues.
Code:
// newproject window is another window ,it has some functionalities like ok and canccel PushButton and other widgets
newproject
::newproject(QWidget *parent
){
ui.setupUi(this);
connect(ui.okButton,SIGNAL(clicked()),this,SLOT(on_okButton_clicked()));
connect(ui.cancelButton,SIGNAL(clicked()),this,SLOT(close()));
}
void newproject::on_okButton_clicked()
{
//ECLogic is the other window(mainwindow)
eclogic->createMainTree();
}
Code:
// ECLlogic is the main window
// below is the slot , it will work when i click on New menuitem
void ECLogic::on_action_New_triggered()
{
NewProject=new newproject(main_tab_widget);
NewProject->show();
}
void ECLogic::createMainTree()
{
//this item has to add in the treewidget
lnx->setText(0,tr("LOGIC"));
ui->treeWidget->addTopLevelItem(lnx);
}
Plz understand the code and let me know further clarifications and how can i solve this problem.
Thanks & Regards,
Mkkguru.
Re: How to add Treewidget Items when clicking on PushButton
Hi,
Code:
connect(ui.okButton,SIGNAL(clicked()),this,SLOT(on_okButton_clicked()));
is not necessary since, setupUi does it for you. Second, go and read some basic C++ book since you obviously don't know the basics.
Where do you initializise eclogic like
Code:
eclogic = new ECLogic;
and in your class eclogic there is no ui pointer! Why your app crashes is that you trying to access on method on a null pointer!
EDIT: Ok, see now that you documented some stuff and I just right know find the necessary information. So I assume that you might have initialized your members but therefore check that and use a debugger to see where your app crashes.
Re: How to add Treewidget Items when clicking on PushButton
Quote:
Originally Posted by
Lykurg
Hi,
Code:
connect(ui.okButton,SIGNAL(clicked()),this,SLOT(on_okButton_clicked()));
is not necessary since, setupUi does it for you. Second, go and read some basic C++ book since you obviously don't know the basics.
Where do you initializise eclogic like
Code:
eclogic = new ECLogic;
and in your class eclogic there is no ui pointer! Why your app crashes is that you trying to access on method on a null pointer!
EDIT: Ok, see now that you documented some stuff and I just right know find the necessary information. So I assume that you might have initialized your members but therefore check that and use a debugger to see where your app crashes.
// eclogic.h
In newproject.h and eclogic .h i initialize eclogic =new ECLogic; in public
i just posted the .cpp code
Code:
//below is the ECLogic window(mainwindow) .cpp
{
ui->setupUi(this);
If you find any mistakes let me know.
thank you.
Re: How to add Treewidget Items when clicking on PushButton
Please also post the corresponding header file. And for a simple debug, try following in your code and show us the output:
Code:
void newproject::on_okButton_clicked()
{
qWarning() << "on_okButton_clicked";
if(!eclogic)
qWarning() << "no pointer!";
eclogic->createMainTree();
}
//---
void ECLogic::createMainTree()
{
qWarning() << "createMainTree";
lnx->setText(0,tr("LOGIC"));
ui->treeWidget->addTopLevelItem(lnx);
}
Re: How to add Treewidget Items when clicking on PushButton
Quote:
Originally Posted by
Lykurg
Please also post the corresponding header file. And for a simple debug, try following in your code and show us the output:
Code:
void newproject::on_okButton_clicked()
{
qWarning() << "on_okButton_clicked";
if(!eclogic)
qWarning() << "no pointer!";
eclogic->createMainTree();
}
//---
void ECLogic::createMainTree()
{
qWarning() << "createMainTree";
lnx->setText(0,tr("LOGIC"));
ui->treeWidget->addTopLevelItem(lnx);
}
Hi,
//below is the newproject.h file
[CODE
]class newproject
: public QDialog {
Q_OBJECT
public:
Ui::NewProject ui;
~newproject();
ECLogic *eclogic;
private:
newproject *NewPrjct;
public slots:
void on_cancelButton_clicked();
void on_okButton_clicked();
[/CODE]
//below is the ECLogic.h
Code:
#include "newproject.h"
#include <QApplication>
#include <QtGui/QMainWindow>
#include <QtGui/QDialog>
#include <QAbstractButton>
#include <QModelIndex>
class ECLogic;
class NewProject;
/*************************
main window(eclogic) Ui name
*************************/
namespace Ui
{
class ECLogicClass;
}
{
Q_OBJECT
public:
~ECLogic();
ECLogic *eclogic;
void createTreewidget();
void create4Bins();
void createMainTree();
/*************************
main window(eclogic) actions slots
*************************/
private slots:
//when i click on new menu,NewProject window will open.
void on_action_New_triggered();
void on_actionAdd_PLC_triggered();
private:
/*************************
main window objects
*************************/
Ui::ECLogicClass *ui;
newproject *NewProject;
ECLogic *eclogic;
Out put is still getting closing when i click on (Ok)pushbutton
Code:
Starting /home/th/Desktop/E.0.1/bin/EL...
on_okButton_clicked
no pointer!
createMainTree
The program has unexpectedly finished.
/home/sumith/Desktop/ECIL-2.0.1/bin/ECIL exited with code 0
Re: How to add Treewidget Items when clicking on PushButton
The code could not be real! The message "no pointer!" indicates that you don't have initialized eclogic! Add to your constructor
Code:
eclogic = new ECLogic;
And therefore I can not understand why "createMainTree" is printed out. So maybe just upload a sample project, that reproduce your problem.
Re: How to add Treewidget Items when clicking on PushButton
Quote:
And therefore I can not understand why "createMainTree" is printed out.
I don't understand why this guy is trying to write an application if he does not know any programming language... He has two eclogic class members: 1 public and 1 private...
Quote:
So maybe just upload a sample project, that reproduce your problem.
This won't help. I tried to understand the code of his project earlier when there was another topic, but it is impossible as this guy has incredible coding style: almost every line starts with different numbers of spaces from the left... he is using global, local and member variables with the same name which he expect to be the same one variable and so on. He has no idea about C++ programming and can't understand that using umbrella doesn't make sense if you don't know how to open it in rainy day!
Re: How to add Treewidget Items when clicking on PushButton
Quote:
Originally Posted by
faldżip
I don't understand why this guy is trying to write an application if he does not know any programming language... He has two eclogic class members: 1 public and 1 private...
This won't help. I tried to understand the code of his project earlier when there was another topic, but it is impossible as this guy has incredible coding style: almost every line starts with different numbers of spaces from the left... he is using global, local and member variables with the same name which he expect to be the same one variable and so on. He has no idea about C++ programming and can't understand that using umbrella doesn't make sense if you don't know how to open it in rainy day!
Hi faldzip,
Thanks for the answering ,As iam a fresher iam in learning stage ,if you know about my issue plz help regrding this,and dont underestimate others..if i confuse you with my code l will post my project ,
thanks & regards,