Results 1 to 5 of 5

Thread: How to set Font for widgets in the parent from a child widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set Font for widgets in the parent from a child widget

    Thanks Lykurg and SantoshReddy.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to set Font for widgets in the parent from a child widget

    Your segmentation faults come from assuming pointers are valid and point to things of certain types:
    Qt Code:
    1. void Class::UpdateFont()
    2. {
    3. QObject *obj = this->parent(); // this can be NULL
    4. QObjectList objlistChildren = obj->children(); // which will crash here
    5. int iCount = objlistChildren.count();
    6.  
    7. for(int iIndex = 0; iIndex < iCount; iIndex++)
    8. {
    9. QObject *temp = objlistChildren[iIndex];
    10. ( (QWidget*)objlistChildren[iIndex] )->setFont(font); // what do you suppose happens if the child is not a QWidget?
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    You should get out of the habit of using C-style casts preferring C++-style casts of the correct type. Casts in general are last-resort mechanisms and worthy of avoidance. In this circumstance you could use qobject_cast and check the cast was successful.

Similar Threads

  1. How to resize parent widget when child widget is resized
    By ainne810329 in forum Qt Programming
    Replies: 4
    Last Post: 29th November 2011, 07:47
  2. Replies: 1
    Last Post: 11th March 2011, 19:34
  3. Replies: 7
    Last Post: 12th January 2011, 22:01
  4. Replies: 7
    Last Post: 14th January 2010, 08:47
  5. initialize child widgets within parent?
    By ucomesdag in forum Newbie
    Replies: 6
    Last Post: 6th June 2006, 08:11

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.