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
QWidget::setLayout: Attempting to set QLayout "" on cctv_form "", which already has a layout
cctv_form.cpp
#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()
{
}
#include "cctv_form.h"
#include <QPushButton>
#include <QHBoxLayout>
cctv_form::cctv_form(QWidget *parent)
: QMainWindow(parent)
{
QPushButton *left = new QPushButton("Right",this);
QPushButton *right = new QPushButton("Right",this);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(left);
layout->addWidget(right);
QWidget *Window = new QWidget();
Window->setLayout(layout);
this->setCentralWidget(window);
}
cctv_form::~cctv_form()
{
}
To copy to clipboard, switch view to plain text mode
cctv_form.h
#ifndef CCTV_FORM_H
#define CCTV_FORM_H
#include <QMainWindow>
{
Q_OBJECT
public:
~cctv_form();
};
#endif // CCTV_FORM_H
#ifndef CCTV_FORM_H
#define CCTV_FORM_H
#include <QMainWindow>
class cctv_form : public QMainWindow
{
Q_OBJECT
public:
cctv_form(QWidget *parent = 0);
~cctv_form();
};
#endif // CCTV_FORM_H
To copy to clipboard, switch view to plain text mode
main.cpp
#include "cctv_form.h"
#include <QApplication>
int main(int argc, char *argv[])
{
cctv_form w;
w.show();
return a.exec();
}
#include "cctv_form.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
cctv_form w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Can anyone point me in the right direction ?
Bookmarks