Attempting to set QLayout on ..., which already has layout
Hi, im trying to make program including simple version of model from Basic Sort/File Model Example , but I get an empty window and warning :
QWidget::setLayout: Attempting to set QLayout "" on EGlowny "", which already has layout
I've checked code few times and I don't see where I did this.
Here you have fragment of my code:
main.cpp
Code:
#include <QApplication>
#include "eglowny.h"
extern void wbaze();
int main(int argc, char *argv[])
{
EGlowny okno;
okno.setSourceModel(asd(&okno));
okno.show();
return app.exec();
}
Eglowny.h
Code:
#ifndef EGLOWNY_H
#define EGLOWNY_H
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QFileDialog>
#include <QMessageBox>
#include <QAbstractItemModel>
#include <QTreeView>
#include <QSortFilterProxyModel>
#include <QComboBox>
#include <QGridLayout>
extern void wbaze
(QString &nazwapliku
);
extern void zapiszbaze
(QString &nazwapliku
);
class ToolBar;
QT_FORWARD_DECLARE_CLASS
(QMenu){
Q_OBJECT
public:
explicit EGlowny
(QWidget *parent
= 0);
private:
void pasekmenu();
void wnetrzeokna();
private slots:
void filterREChanged();
void filterColumnChanged();
};
#endif // EGLOWNY_H
Eglowny.cpp
Code:
#include "eglowny.h"
EGlowny
::EGlowny(QWidget *parent
) :{
pasekmenu();
wnetrzeokna();
setWindowTitle("Program");
resize(800, 600);
}
void EGlowny::wnetrzeokna()
{
proxyModel->setDynamicSortFilter(true);
proxyView->setRootIsDecorated(false);
proxyView->setAlternatingRowColors(true);
proxyView->setModel(proxyModel);
proxyView->setSortingEnabled(true);
filterPatternLabel
= new QLabel(tr
("Filter Pattern: "));
filterColumnComboBox->addItem(tr("1"));
filterColumnComboBox->addItem(tr("2"));
filterColumnComboBox->addItem(tr("3"));
filterColumnLabel
= new QLabel(tr
("Filter column: "));
connect (filterPatternLineEdit,
SIGNAL(textChanged
(QString)),
this,
SLOT(filterREChanged
()));
connect (filterColumnComboBox, SIGNAL(currentIndexChanged(int)),this,SLOT(filterColumnChanged()));
proxyLayout->addWidget(proxyView, 0, 0, 1, 3);
proxyLayout->addWidget(filterPatternLabel, 1, 0);
proxyLayout->addWidget(filterPatternLineEdit, 1, 1, 1, 2);
proxyLayout->addWidget(filterColumnLabel, 2, 0);
proxyLayout->addWidget(filterColumnComboBox, 2, 1, 1, 2);
setLayout(proxyLayout);
proxyView->sortByColumn(1,Qt::AscendingOrder);
filterColumnComboBox->setCurrentIndex(1);
}
void EGlowny::pasekmenu()
{
QMenu *Plik
= menuBar
()->addMenu
(tr
("Baza"));
QAction *action
= Plik
->addAction
(tr
("..."));
}
baz.h - from this file comes extern functions
Code:
{
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("Subject"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Sender"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("Date"));
dodajwpis(model, "as", "qb", "sac","wd");
dodajwpis(model, "aa", "bs", "sc","asd");
dodajwpis(model, "xw", "yx", "sz","saa");
return model;
}
{
model->insertRow(0);
model->setData(model->index(0,0),wpistyp);
model->setData(model->index(0,1),wpisnazwa);
model->setData(model->index(0,2),wpiszaw);
model->setData(model->index(0,3),wpiskraj);
}
Re: Attempting to set QLayout on ..., which already has layout
EGlowny derives from QMainWindow which already has a layout with a center widget, a dockable toolbar and menubar. The code you provided didn't compile, but what you need to do is to set up your layout on the centralWidget() instead of the main window. You could also derive EGlowny from a QWidget instead of a QMainWindow if you don't need the facilities of the QMainWindow.
Re: Attempting to set QLayout on ..., which already has layout
Thank you. Problem solved