QLayout: Attempting to add QLayout "" to QMainWindow "", which already has a layout



  • Hello,
    I have problems regarding to layout of QMainWindow. I know QMainWindow has already layout, but if I try to create QHBoxLayout, I get this warning:

    QLayout: Attempting to add QLayout "" to QMainWindow "", which already has a layout

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) 
    {
        QStackedWidget *stackedWidget = new QStackedWidget(this);
        QWidget *widget = new QWidget();
        QMenu * fileMenu = menuBar()->addMenu(tr("&File"));
        QHBoxLayout *layout = new QHBoxLayout(this);  
        // QTreeWidget *tree   = new QTreeWidget(this);
    }
    
    

    mainwindow.h

    class MainWindow : public QMainWindow
    {
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private:
    
    };
    

    pro file:

    QT       += core gui xml network testlib
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = SCADA
    TEMPLATE = app
    
    
    SOURCES +=  main.cpp\
                mainwindow.cpp
    
    HEADERS  += mainwindow.h 
    
    


  • Sorry,
    I solved the Problem.

    QHBoxLayout *layout = new QHBoxLayout(widget);  // not this :)
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.