Results 1 to 3 of 3

Thread: Cant use QWidget::setParent().

  1. #1
    Join Date
    Mar 2014
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Cant use QWidget::setParent().

    Hi.

    I have a new class called Piece, tried to inherit QLabel or QPushButton, everything is good, but once I try to set a parent (QWidget *container) its says

    error: "void QWidget::setParent(QWidget*)' is inaccessible
    void setParent(QWidget *parent);
    ^."

    After see that QLabel wasn't working, tried with QPushButton and happened the same thing.

    My Example Class:

    Qt Code:
    1. #ifndef PIECE_H
    2. #define PIECE_H
    3. #include <QPushButton>
    4. #include <QMouseEvent>
    5.  
    6. class Piece : QPushButton{
    7. Q_OBJECT
    8. public:
    9. Piece();
    10.  
    11.  
    12. };
    13. #endif // PIECE_H
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Cant use QWidget::setParent().

    Your code uses private inheritance, all the methods of the base class are then private.

    You want public inheritance

    Qt Code:
    1. class Piece : public QPushButton{
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    vitaR (2nd July 2014)

  4. #3
    Join Date
    Mar 2014
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Cant use QWidget::setParent().

    Thanks, it works.

Similar Threads

  1. QObject::setParent across threads.
    By psih128 in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2014, 16:01
  2. What happened when Qt Widget SetParent(NULL)
    By familymrfan in forum Newbie
    Replies: 1
    Last Post: 22nd October 2013, 06:54
  3. hwnd to qwidget setparent error
    By cic in forum Qwt
    Replies: 1
    Last Post: 27th August 2013, 14:40
  4. Replies: 2
    Last Post: 18th August 2011, 07:26
  5. Qt widget setParent
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 30th November 2007, 20:38

Tags for this Thread

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.