2017-02-04 86 views
-1

我試圖將項目添加到一個QHBox沒有匹配的功能,但我不斷收到錯誤:Qt的錯誤:錯誤:調用「QHBoxLayout,負責::的addItem(QPushButton *)」

/media/root/5431214957EBF5D7/projects/c/qt/tools/plugandpaint/app/mainwindow.cpp:36: error: no matching function for call to ‘QHBoxLayout::addItem(QPushButton*&)’ 
    hlayout->addItem(m_button); 
          ^

什麼我可能做錯了嗎?

mainwindow.h

#ifndef MAINWINDOW_H 
#define MAINWINDOW_H 


#include <QHBoxLayout> 

class PaintArea; 

class MainWindow : public QMainWindow 
{ 
    Q_OBJECT 

public: 
    MainWindow(); 

private slots: 
    void handleButton(); 
    // Other slots 

private: 
    PaintArea *paintArea; 
    QHBoxLayout *hlayout; 

    // Other private items 
}; 

#endif 

mainwindow.cpp

MainWindow::MainWindow() : 
    paintArea(new PaintArea), 
    scrollArea(new QScrollArea) 
{ 

    // Create the button, make "this" the parent 
    m_button = new QPushButton("My Button", this); 
    // set size and location of the button 
    m_button->setGeometry(QRect(QPoint(100, 100), QSize(200, 50))); 

    // Connect button signal to appropriate slot 
    connect(m_button, SIGNAL (released()), this, SLOT (handleButton())); 

    hlayout = new QHBoxLayout; 
    hlayout -> addItem(m_button); 
    hlayout -> addItem(paintArea); 

    scrollArea->setWidget(hlayout); 
+0

請問您可以添加更多的源代碼。我甚至看不到'm_button'聲明。 –

+0

我剛剛做了@RealFresh –

+0

錯誤信息的哪個部分是你正在努力的?您是否閱讀過有關課程的文檔? – juanchopanza

回答

0

它應該是:

hlayout->addWidget(m_button); 

順便一提,那this按鈕旁邊名字是沒有必要的。層次結構中的佈局和小部件負責所有權。