Results 1 to 9 of 9

Thread: Could I manage the resource of Qt without try and catch?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Could I manage the resource of Qt without try and catch?

    Qt Code:
    1. class Wizard : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Wizard(QWidget *parent);
    7.  
    8. private slots:
    9. void what_ever();
    10.  
    11. private:
    12. QPushButton *what_ever;
    13. };
    14.  
    15. Wizard::Wizard( QWidget *parent ) : QDialog(parent)
    16. {
    17. QGridLayout *layout = new QGridLayout( this );
    18.  
    19. QScopedPointer<QTextEdit> textEdit(new QTextEdit);
    20. layout->addWidget( textEdit.take(), 0, 0, 1, 2 );
    21.  
    22. what_ever = new QPushButton("whatever");
    23. layout->addWidget(what_ever, 0, 1, 1, 1);
    24.  
    25. connect(what_ever, SIGNAL(clicked()), this, SLOT(what_ever()));
    26. }
    27.  
    28. void Wizard::what_ever()
    29. {
    30. //blah blah blah
    31. }
    To copy to clipboard, switch view to plain text mode 

    I have some problems about the codes.

    1 : What if textEdit throw exception?
    If "textEdit" throw exception, that means the
    destructor of Wizard would not be called,
    What would Qt handle the resource of "layout"?

    2 : Could I initialize "what_ever" like this?
    layout->addWidget(what_ever = new QPushButton("whatever"), 0, 1, 1, 1);
    Is this safe in Qt4(4.8)?Would it have any change to cause memory leak?

    Thanks a lot
    Last edited by stereoMatching; 8th April 2012 at 09:37.

Similar Threads

  1. best way to manage forms?
    By skuda in forum Qt Programming
    Replies: 4
    Last Post: 7th December 2009, 08:38
  2. Use Organigramm to manage database
    By Mefisto in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2009, 10:45
  3. What is the best way to manage memory across threads?
    By bughunter2 in forum Qt Programming
    Replies: 2
    Last Post: 4th January 2009, 23:53
  4. Best way to manage application icons
    By SiLiZiUMM in forum Qt Programming
    Replies: 0
    Last Post: 23rd April 2008, 14:28
  5. How to manage QPainter?
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:20

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.