I want to implement a vertical scroll bar. I have implemented layouts for this(see the attached layouts.jpg), and also scroll area(see snippet in below code). Yet, when I run, the window does not have menubar. What am I missing here? I tried adding the menubar and submenus through Qt designer, as well as through code, but the window does not show the menubar.

If i use scroll area snippet, i can use the scrollbar, but don't see menubar. However If i comment out the scroll area snippet, i can see the menubar, but lose the scroll bar. I need both of them. How to solve this?
layouts.JPG

Here is the code:- mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QScrollArea>
  6. namespace Ui {
  7. class MainWindow;
  8. }
  9.  
  10. class MainWindow : public QMainWindow
  11. {
  12. Q_OBJECT
  13.  
  14. public:
  15. explicit MainWindow(QWidget *parent = 0);
  16. ~MainWindow();
  17.  
  18. private:
  19. Ui::MainWindow *ui;
  20.  
  21.  
  22. };
  23.  
  24. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 
mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent) :
  5. QMainWindow(parent),
  6. ui(new Ui::MainWindow)
  7. {
  8. ui->setupUi(this);
  9. layout()->setMenuBar(menuBar());
  10. QMenu *viewMenu;
  11. viewMenu = menuBar()->addMenu("VIEW");
  12. QMenu *resolutionSubMenu = viewMenu->addMenu("Resolution");
  13. QAction *QVGA = resolutionSubMenu->addAction("QVGA");
  14.  
  15.  
  16. QImage image(":\\image.jpg");
  17. ui->referenceImageLabel->setPixmap(QPixmap::fromImage(image));
  18. ui->deltaImageLabel->setPixmap(QPixmap::fromImage(image));
  19. ui->reconstructedImageLabel->setPixmap(QPixmap::fromImage(image));
  20. ui->referenceImageLabel->setMinimumSize(480, 640);ui->referenceImageLabel->setMinimumSize(480, 640);ui->referenceImageLabel->setMinimumSize(480, 640);
  21.  
  22. /*Scroll area snippet*/
  23. QScrollArea *p_ScrollArea = new QScrollArea(this);
  24. p_ScrollArea->setAutoFillBackground(true);
  25. p_ScrollArea->setMinimumSize(width(), height());
  26. p_ScrollArea->setWidget(ui->centralWidget);
  27.  
  28. }
  29.  
  30. MainWindow::~MainWindow()
  31. {
  32. delete ui;
  33. }
To copy to clipboard, switch view to plain text mode 
main.cpp

Qt Code:
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. MainWindow w;
  8. w.show();
  9.  
  10. return a.exec();
  11. }
To copy to clipboard, switch view to plain text mode