Results 1 to 7 of 7

Thread: Is it possible to get QToolBox widget's page name, in run time?

  1. #1
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Is it possible to get QToolBox widget's page name, in run time?

    I have a QToolBox and adding pages to it in runtime
    Each page has scroll area, inside scroll area comboboxes area dded at runtime
    Is it possible to get page name of any particular combobox?

    i tried code shown below, but it didnt work...


    Qt Code:
    1. QToolBox *temp=new QToolBox;
    2. temp=dynamic_cast<QToolBox *>(tempCheckBox->parentWidget()->parentWidget());
    3. QString fname=temp->itemText(temp->currentIndex());
    4. std::cout<<"FILE NAME:"<<fname.toStdString()<<endl;
    To copy to clipboard, switch view to plain text mode 


    also tried using
    Qt Code:
    1. temp=dynamic_cast<QToolBox *>(tempCheckBox->parentWidget());
    To copy to clipboard, switch view to plain text mode 

    but program was crashing both time....

  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: Is it possible to get QToolBox widget's page name, in run time?

    Well in your first example you are creating a memory leak. Beside that, are you sure tempCheckBox isn't a null pointer?

  3. #3
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is it possible to get QToolBox widget's page name, in run time?

    Ya thats not null pointer...

  4. #4
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is it possible to get QToolBox widget's page name, in run time?

    I tried as below….i got pointer to QToolBox….
    But whenever i try to get page name of any widget it just returns nothing…always index is -1….
    please tell me whats wrong here?


    Qt Code:
    1. void FilterColl::getParentPage(QCheckBox *tempCheckBox)
    2. {
    3. QToolBox *temp=new QToolBox;
    4. if(!tempCheckBox)
    5. {
    6. cout<<"no check box"<<endl;
    7. return;
    8. }
    9. QWidget *parent=tempCheckBox->parentWidget();
    10. if(!parent)
    11. {
    12. cout<<"np page for this widget"<<endl;
    13. return;
    14. }
    15.  
    16. while(parent)
    17. { QString classname=parent->metaObject()->className();
    18. cout<<"the parent class is:"<<classname.toStdString() <<endl;
    19. if(classname=="QToolBox")
    20. { temp=dynamic_cast<QToolBox *>(parent);
    21. std::cout<<"the tool box page name:"<<temp->itemText(temp->indexOf(tempCheckBox)).toStdString()<<endl;
    22. cout<<"the index is :"<<temp->indexOf(tempCheckBox)<<endl;
    23. }
    24. parent=parent->parentWidget();
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    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: Is it possible to get QToolBox widget's page name, in run time?

    You are still producing a memory leak, and your code works if you fill the QToolBox correctly!
    Qt Code:
    1. #include <QtGui>
    2.  
    3.  
    4. void getParentPage(QCheckBox *tempCheckBox)
    5. {
    6. QToolBox *temp = 0;
    7. if (!tempCheckBox) {
    8. qWarning() << "no check box";
    9. return;
    10. }
    11. QWidget *parent = tempCheckBox->parentWidget();
    12. if (!parent) {
    13. qWarning() << "np page for this widget";
    14. return;
    15. }
    16.  
    17. while (parent) {
    18. QString classname = parent->metaObject()->className();
    19. qWarning() << "the parent class is:" << classname;
    20. if (classname == "QToolBox") {
    21. temp = dynamic_cast<QToolBox *>(parent);
    22. qWarning() << "the tool box page name:" << temp->itemText(temp->indexOf(tempCheckBox));
    23. qWarning() << "the index is :" << temp->indexOf(tempCheckBox);
    24. }
    25. parent = parent->parentWidget();
    26. }
    27. }
    28.  
    29. int main(int argc, char **argv)
    30. {
    31. QApplication app(argc, argv);
    32.  
    33. QToolBox tb(&w);
    34. tb.insertItem(0, &b, "sample text");
    35. getParentPage(&b);
    36.  
    37. return 0;
    38. }
    To copy to clipboard, switch view to plain text mode 

    gives
    the parent class is: "QWidget"
    the parent class is: "QScrollArea"
    the parent class is: "QToolBox"
    the tool box page name: "sample text"
    the index is : 0
    the parent class is: "QWidget"

  6. #6
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is it possible to get QToolBox widget's page name, in run time?

    Quote Originally Posted by Lykurg View Post
    You are still producing a memory leak,
    Sorry i'm new to Qt, please let me how to avoid memory leak..?
    Where i'm producing memory leak in this program?
    any links to learn abt that?

  7. #7
    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: Is it possible to get QToolBox widget's page name, in run time?

    Why you write
    Qt Code:
    1. QToolBox *temp=new QToolBox;
    To copy to clipboard, switch view to plain text mode 
    ? There you create a tool box without deleting it. This creates a memory leak...

Similar Threads

  1. Replies: 6
    Last Post: 9th April 2011, 19:23
  2. Replies: 1
    Last Post: 23rd December 2010, 09:35
  3. how do add a page in QToolBox
    By kavinsiva in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2009, 05:37
  4. Displaying Page Number on a widget
    By LiCodeX in forum Newbie
    Replies: 1
    Last Post: 23rd August 2007, 08:34
  5. Widget to display an HTML page ?
    By probine in forum Qt Tools
    Replies: 3
    Last Post: 11th October 2006, 18:55

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.