2017-02-06 3 views
-1

Ich versuche, eine QWidget zu schaffen, aber ich halte den Fehler bekommen:Wie ein QWidget erstellen

/media/root/5431214957EBF5D7/projects/c/qt/tools/plugandpaint/app/mainwindow.cpp:53: error: no matching function for call to ‘QWidget::setLayout(QScrollArea*&)’ 
    mainWin -> setLayout(scrollArea); 
            ^

mainwindow.cpp

#include "mainwindow.h" 

#include <QScrollArea> 
#include <QApplication> 

MainWindow::MainWindow() : 
    scrollArea(new QScrollArea) 
{ 
    mainWin = new QWidget(); 

    // 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())); 

    label = new QLabel(QApplication::translate("windowlayout", "Name:")); 
    lineEdit = new QLineEdit(); 

    layout = new QHBoxLayout(); 
    layout->addWidget(label); 
    layout->addWidget(lineEdit); 

    scrollArea->setLayout(layout); 

    mainWin -> setLayout(scrollArea); 
} 

mainwindow.h

#ifndef MAINWINDOW_H 
#define MAINWINDOW_H 

#include <QPushButton> 
#include <QHBoxLayout> 
#include <QLabel> 
#include <QLineEdit> 

class QActionGroup; 
class QScrollArea; 

class MainWindow : public QWidget 
{ 
    Q_OBJECT 

public: 
    MainWindow(); 

private: 

    QWidget *mainWin; 
    QScrollArea *scrollArea; 
    QStringList pluginFileNames; 

    QPushButton *m_button; 
    QLabel *label; 
    QLineEdit *lineEdit; 
    QHBoxLayout *layout; 

    QVBoxLayout *vBox; 
}; 

#endif 

Hier ist, wie ich es versuche ruft alles zusammen:

#include "mainwindow.h" 
#include <QtPlugin> 
#include <QApplication> 

#include <QDesktopWidget> 

Q_IMPORT_PLUGIN(BasicToolsPlugin) 

int main(int argc, char *argv[]) 
{ 
    QApplication app(argc, argv); 
    MainWindow window; 

    QDesktopWidget dw; 

    int x=dw.width()*0.7; 
    int y=dw.height()*0.7; 
    window.setFixedSize(x,y); 

    window.show(); 


    return app.exec(); 
} 

Was mache ich falsch? Ich bin ein totaler Qt/C++ Neuling, wenn das Problem zu offensichtlich ist.

Vielen Dank im Voraus.

+0

Bitte lesen Sie das Handbuch. Die Warnung sagt alles: qwidget hat keine Methode, um das Layout auf einen Bildlaufbereich zu setzen. – user3528438

+0

'setLayout' fragt nach einem 'QLayout'-Zeiger, geben Sie ihm einen' QScrollArea'-Zeiger. Der Compiler mag das nicht. –

+0

-1 Es tut mir leid, aber die Frage stimmt überhaupt nicht mit Ihrem Problem überein, und es ist schwierig zu sagen, was Sie überhaupt erreichen wollen, indem Sie das Layout des Einstellungsfensters auf ... einen Bildlaufbereich setzen. Bitte komprimiere es auf MCVE, beschränke die Frage, lies die Dokumentation, etc. – cubuspl42

Antwort

0

Zunächst einmal, ich kann nicht überall eine

new QScrollearea() 

Zweitens sehen:

QScrollArea*& 

vor allem die

*&

ist die meiste Zeit ein Hinweis für einen Zeiger/Referenzabweichung

Verwandte Themen