Results 1 to 20 of 22

Thread: Problems with setCentralWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    371
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setCentralWidget

    Plain old casting and doubble inheritance do not work as expected. Look at this line:

    Qt Code:
    1. mw.setCentralWidget((QWidget*)c);
    To copy to clipboard, switch view to plain text mode 

    Try using qobject_cast or dynamic_cast:
    Qt Code:
    1. mw.setCentralWidget( qobject_cast<QWidget*>(c) );
    2. mw.setCentralWidget( dynamic_cast<QWidget*>(c) );
    To copy to clipboard, switch view to plain text mode 

    or just no cast at all:
    Qt Code:
    1. mw.setCentralWidget( c );
    To copy to clipboard, switch view to plain text mode 

    And do try to put the QObject first in the double inheritance.

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

    Rockem (8th March 2008)

  3. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,369
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems with setCentralWidget

    qobject_cast won't work because CompView is not a QObject. dynamic_cast seems to work.

  4. #3
    Join Date
    Feb 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setCentralWidget

    yea, dynamic_cast works great !!!

    thanx

Similar Threads

  1. Replies: 2
    Last Post: 8th March 2007, 22:22
  2. Utf8 problems
    By cristiano in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2006, 00:14
  3. Problems building mysql plugin for Qt 4.1.2 on windows XP
    By Philip_Anselmo in forum Installation and Deployment
    Replies: 3
    Last Post: 17th May 2006, 15:38
  4. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39
  5. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28

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.