Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] QWidget * parameter for any widget
Forum Updated to NodeBB v4.3 + New Features

[solved] QWidget * parameter for any widget

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T3STYT Offline
    T3STYT Offline
    T3STY
    wrote on last edited by
    #1

    I have a class made like this:
    @class test : public QWidget{
    public:
    test(QWidget * parent=nullptr, Qt::WindowFlags flags=0);
    ~test();
    void addWid(QWidget *);

    private:
    QHBoxLayout * viewLayout;
    QWidget * viewportWidget;
    QScrollArea * viewportScroll;
    void resizeEvent(QResizeEvent * );
    };@

    The addWid() method is used to add more widgets to the viewLayout; it's just an external access method for viewLayout->addWidget() because viewLayout is private. Unfortunately it's not working as expected. When I call the method with a QWidget pointer it works just fine, but if I call it with a QPushButton * or any other widget pointer, the compiler complains that it cannot find a proper method to call for a QPushButton * parameter (or, whichever is the object type).

    In the QBoxLayout class documentation I see the addWidget() method is defined with a QWidget * parameter, just like I did:
    @void QBoxLayout::addWidget(QWidget * widget, int stretch = 0, Qt::Alignment alignment = 0)@

    So what am I doing wrong ?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      In this code, nothing is wrong. The problem may be in the calling code, if that code does not have access to the knowledge that a QPushButton is a QWidget.

      1 Reply Last reply
      0
      • T3STYT Offline
        T3STYT Offline
        T3STY
        wrote on last edited by
        #3

        I figured it out. As you suspected Andre, the calling was wrong. I was using a function call as parameter, it should have returned a QWidget * but instead it returned a QWidget **, so it totally mismatched the addWid() method.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved