Problems Creating layout on MainWindow
Ok currently just testing a basic implementation as having problems with this section of the code in my main program.
Below is a simple class that just contains a couple of buttons created in code. However when I try to add them to either the central widget or to a layout the code fails with
Quote:
QWidget::setLayout: Attempting to set QLayout "" on cctv_form "", which already has a layout
cctv_form.cpp
Code:
#include "cctv_form.h"
#include <QPushButton>
#include <QHBoxLayout>
cctv_form
::cctv_form(QWidget *parent
){
layout->addWidget(left);
layout->addWidget(right);
Window->setLayout(layout);
this->setCentralWidget(window);
}
cctv_form::~cctv_form()
{
}
cctv_form.h
Code:
#ifndef CCTV_FORM_H
#define CCTV_FORM_H
#include <QMainWindow>
{
Q_OBJECT
public:
~cctv_form();
};
#endif // CCTV_FORM_H
main.cpp
Code:
#include "cctv_form.h"
#include <QApplication>
int main(int argc, char *argv[])
{
cctv_form w;
w.show();
return a.exec();
}
Can anyone point me in the right direction ?
Re: Problems Creating layout on MainWindow
Strange.
Try creating the buttons with their actual parent instead.
Cheers,
_
Re: Problems Creating layout on MainWindow
Are you using Qt Designer to create your MainWindow .ui file? Are you specifying a layout in that for the central widget?
Is this your actual code? You have a QWidget instance named "Window" (with an uppercase "W") and you're calling setCentralWidget( window ) (with a lowercase "w"). Unless you have lowercase "window" declared somewhere, the code you posted won't compile.