Results 1 to 20 of 42

Thread: QTreeWidget clicked signal

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #37
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 140 Times in 132 Posts

    Default Re: QTreeWidget clicked signal

    Quote Originally Posted by mkkguru View Post
    Hi,
    I didnt mention any type to Item and PLC ,i just created as QTreewidgetItem *item and QTreeWidgetItem *plc
    I mean C++ type... To make you things easier I can say that in this code:
    Qt Code:
    1. void ECLogic::showItem(QTreeWidgetItem* item )
    2. {
    3. if(item=="PLC")
    4. {
    5. PLCconfig=new plcconfiguration();
    6. main_tab_widget->insertTab(0,PLCconfig, "PLC");
    7. main_tab_widget->setCurrentIndex(0);
    8. PLCconfig->show();
    9. }
    10. else if(item==lnx)
    11. {
    12. ECLogic_Lnx=new eclogic_lnx(main_tab_widget);
    13. ECLogic_Lnx->setWindowTitle(QString("ECLOGIC-LNX"));
    14. ECLogic_Lnx->show();
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    item's type is QTreeWidgetItem* and "PLC" is const char *, so both are pointers. Do you want to compare two memory addresses of two completely different things? I don't think so...
    And again:
    i just created as QTreewidgetItem *item and QTreeWidgetItem *plc
    You have created them in another method as local variables so they not exist where you want to reference them. They are dead :]

    Your problem now is pure C++ issue. Please revise your C++ basics, like local variables, scopes, referencing pointers and so on.

    And your project your slot showItem looks:
    Qt Code:
    1. void ECLogic::showItem(QTreeWidgetItem* item )
    2. {
    3.  
    4. ECLogic_Lnx=new eclogic_lnx(main_tab_widget);
    5. ECLogic_Lnx->setWindowTitle(QString("ECLOGIC-LNX"));
    6. ECLogic_Lnx->show();
    7.  
    8. item << "PLC" << "CPU CONFIGURATION" << "PROGRAM VARIABLE CONFIGURATION" << "IO CONFIGURATION"
    9. << "BIN" << "SLOT" <<"LADDER PROGRAM";
    10.  
    11. if(item=="PLC")
    12. {
    13. PLCconfig=new plcconfiguration();
    14. main_tab_widget->insertTab(0,PLCconfig, "PLC");
    15. main_tab_widget->setCurrentIndex(0);
    16. PLCconfig->show();
    17. }
    18. else if(item==lnx)
    19. {
    20. ECLogic_Lnx=new eclogic_lnx(main_tab_widget);
    21. ECLogic_Lnx->setWindowTitle(QString("ECLOGIC-LNX"));
    22. ECLogic_Lnx->show();
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 
    Which does not make sense at all.

    EDIT:
    Oops now I found that there is another lnx variable which is class member - that would be better, but when you are creating new QTreeWidgetItem you are assigning it to the local variable with the same name (lnx) so your member variable lnx is always unassigned and referencing it will cause segmentation fault.
    Last edited by faldzip; 28th January 2010 at 16:04.
    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.

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

    mkkguru (30th January 2010)

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
  •  
Qt is a trademark of The Qt Company.