Results 1 to 8 of 8

Thread: How to add Treewidget Items when clicking on PushButton

  1. #1
    Join Date
    Oct 2009
    Posts
    35
    Thanks
    12
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11

    Post 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.

    Qt Code:
    1. // newproject window is another window ,it has some functionalities like ok and canccel PushButton and other widgets
    2. newproject::newproject(QWidget *parent)
    3. : QDialog(parent)
    4. {
    5. ui.setupUi(this);
    6. connect(ui.okButton,SIGNAL(clicked()),this,SLOT(on_okButton_clicked()));
    7. connect(ui.cancelButton,SIGNAL(clicked()),this,SLOT(close()));
    8. }
    9.  
    10. void newproject::on_okButton_clicked()
    11. {
    12. //ECLogic is the other window(mainwindow)
    13. eclogic->createMainTree();
    14. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // ECLlogic is the main window
    2. // below is the slot , it will work when i click on New menuitem
    3. void ECLogic::on_action_New_triggered()
    4. {
    5. NewProject=new newproject(main_tab_widget);
    6. NewProject->show();
    7.  
    8. }
    9. void ECLogic::createMainTree()
    10. {
    11. //this item has to add in the treewidget
    12. QTreeWidgetItem *lnx = new QTreeWidgetItem(ui->treeWidget);
    13. lnx->setText(0,tr("LOGIC"));
    14. ui->treeWidget->addTopLevelItem(lnx);
    15. }
    To copy to clipboard, switch view to plain text mode 

    Plz understand the code and let me know further clarifications and how can i solve this problem.

    Thanks & Regards,
    Mkkguru.
    Last edited by mkkguru; 10th February 2010 at 09:51.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to add Treewidget Items when clicking on PushButton

    Hi,
    Qt Code:
    1. connect(ui.okButton,SIGNAL(clicked()),this,SLOT(on_okButton_clicked()));
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. eclogic = new ECLogic;
    To copy to clipboard, switch view to plain text mode 
    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.

  3. The following user says thank you to Lykurg for this useful post:

    mkkguru (10th February 2010)

  4. #3
    Join Date
    Oct 2009
    Posts
    35
    Thanks
    12
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11

    Default Re: How to add Treewidget Items when clicking on PushButton

    Quote Originally Posted by Lykurg View Post
    Hi,
    Qt Code:
    1. connect(ui.okButton,SIGNAL(clicked()),this,SLOT(on_okButton_clicked()));
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. eclogic = new ECLogic;
    To copy to clipboard, switch view to plain text mode 
    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


    Qt Code:
    1. //below is the ECLogic window(mainwindow) .cpp
    2. ECLogic::ECLogic(QWidget *parent)
    3. : QMainWindow(parent) , ui(new Ui::ECLogicClass)
    4. {
    5. ui->setupUi(this);
    To copy to clipboard, switch view to plain text mode 

    If you find any mistakes let me know.

    thank you.
    Last edited by mkkguru; 10th February 2010 at 10:35.

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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:
    Qt Code:
    1. void newproject::on_okButton_clicked()
    2. {
    3. qWarning() << "on_okButton_clicked";
    4. if(!eclogic)
    5. qWarning() << "no pointer!";
    6. eclogic->createMainTree();
    7. }
    8. //---
    9. void ECLogic::createMainTree()
    10. {
    11. qWarning() << "createMainTree";
    12. QTreeWidgetItem *lnx = new QTreeWidgetItem(ui->treeWidget);
    13. lnx->setText(0,tr("LOGIC"));
    14. ui->treeWidget->addTopLevelItem(lnx);
    15. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Oct 2009
    Posts
    35
    Thanks
    12
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11

    Default Re: How to add Treewidget Items when clicking on PushButton

    Quote Originally Posted by Lykurg View Post
    Please also post the corresponding header file. And for a simple debug, try following in your code and show us the output:
    Qt Code:
    1. void newproject::on_okButton_clicked()
    2. {
    3. qWarning() << "on_okButton_clicked";
    4. if(!eclogic)
    5. qWarning() << "no pointer!";
    6. eclogic->createMainTree();
    7. }
    8. //---
    9. void ECLogic::createMainTree()
    10. {
    11. qWarning() << "createMainTree";
    12. QTreeWidgetItem *lnx = new QTreeWidgetItem(ui->treeWidget);
    13. lnx->setText(0,tr("LOGIC"));
    14. ui->treeWidget->addTopLevelItem(lnx);
    15. }
    16.  
    17. Hi,
    18.  
    19. //below is the newproject.h file
    20. [CODE]class newproject : public QDialog
    21. {
    22. Q_OBJECT
    23. public:
    24. Ui::NewProject ui;
    25. newproject(QWidget *parent = 0);
    26. ~newproject();
    27. ECLogic *eclogic;
    28.  
    29. private:
    30.  
    31. newproject *NewPrjct;
    32.  
    33. public slots:
    34. void on_cancelButton_clicked();
    35. void on_okButton_clicked();
    To copy to clipboard, switch view to plain text mode 
    [/CODE]
    //below is the ECLogic.h
    Qt Code:
    1. #include "newproject.h"
    2.  
    3. #include <QApplication>
    4. #include <QtGui/QMainWindow>
    5. #include <QtGui/QDialog>
    6.  
    7. #include <QAbstractButton>
    8. #include <QModelIndex>
    9.  
    10. class ECLogic;
    11. class NewProject;
    12.  
    13. /*************************
    14.  main window(eclogic) Ui name
    15.  *************************/
    16. namespace Ui
    17. {
    18. class ECLogicClass;
    19. }
    20.  
    21. class ECLogic : public QMainWindow
    22. {
    23. Q_OBJECT
    24.  
    25. public:
    26. ECLogic(QWidget *parent = 0);
    27. ~ECLogic();
    28. ECLogic *eclogic;
    29. void createTreewidget();
    30. void create4Bins();
    31. void createMainTree();
    32.  
    33. /*************************
    34.   main window(eclogic) actions slots
    35.   *************************/
    36. private slots:
    37. //when i click on new menu,NewProject window will open.
    38. void on_action_New_triggered();
    39. void on_actionAdd_PLC_triggered();
    40. private:
    41. /*************************
    42.   main window objects
    43.   *************************/
    44. Ui::ECLogicClass *ui;
    45. newproject *NewProject;
    46. ECLogic *eclogic;
    To copy to clipboard, switch view to plain text mode 

    Out put is still getting closing when i click on (Ok)pushbutton
    Qt Code:
    1. Starting /home/th/Desktop/E.0.1/bin/EL...
    2. on_okButton_clicked
    3. no pointer!
    4. createMainTree
    5.  
    6. The program has unexpectedly finished.
    7.  
    8. /home/sumith/Desktop/ECIL-2.0.1/bin/ECIL exited with code 0
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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
    Qt Code:
    1. eclogic = new ECLogic;
    To copy to clipboard, switch view to plain text mode 
    And therefore I can not understand why "createMainTree" is printed out. So maybe just upload a sample project, that reproduce your problem.

  8. #7
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to add Treewidget Items when clicking on PushButton

    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...
    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!
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  9. The following user says thank you to faldzip for this useful post:

    mkkguru (11th February 2010)

  10. #8
    Join Date
    Oct 2009
    Posts
    35
    Thanks
    12
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11

    Default Re: How to add Treewidget Items when clicking on PushButton

    Quote Originally Posted by faldżip View Post
    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,

Similar Threads

  1. Replies: 8
    Last Post: 1st October 2015, 07:23
  2. Double Clicking Pro File
    By BalaQT in forum Installation and Deployment
    Replies: 2
    Last Post: 18th November 2009, 05:23
  3. Replies: 1
    Last Post: 28th July 2009, 06:58
  4. Problem editing TreeWidget items
    By Moezzie in forum Qt Programming
    Replies: 3
    Last Post: 15th December 2007, 21:22
  5. Replies: 2
    Last Post: 14th November 2006, 11:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.