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
#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();
}
#include <QApplication>
#include "eglowny.h"
extern QAbstractItemModel *asd(QObject *parent);
extern void wbaze();
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
EGlowny okno;
okno.setSourceModel(asd(&okno));
okno.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Eglowny.h
#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
#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)
QT_FORWARD_DECLARE_CLASS(QSignalMapper)
class EGlowny : public QMainWindow
{
Q_OBJECT
public:
explicit EGlowny(QWidget *parent = 0);
void setSourceModel(QAbstractItemModel *model);
private:
void pasekmenu();
void wnetrzeokna();
QSortFilterProxyModel *proxyModel;
QGridLayout *proxyLayout;
QTreeView *proxyView;
QLabel *filterPatternLabel;
QLabel *filterColumnLabel;
QLineEdit *filterPatternLineEdit;
QComboBox *filterColumnComboBox;
private slots:
void filterREChanged();
void filterColumnChanged();
};
#endif // EGLOWNY_H
To copy to clipboard, switch view to plain text mode
Eglowny.cpp
#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
("..."));
}
#include "eglowny.h"
EGlowny::EGlowny(QWidget *parent) :
QMainWindow(parent)
{
pasekmenu();
wnetrzeokna();
setWindowTitle("Program");
resize(800, 600);
}
void EGlowny::wnetrzeokna()
{
proxyModel = new QSortFilterProxyModel;
proxyModel->setDynamicSortFilter(true);
proxyView = new QTreeView;
proxyView->setRootIsDecorated(false);
proxyView->setAlternatingRowColors(true);
proxyView->setModel(proxyModel);
proxyView->setSortingEnabled(true);
filterPatternLineEdit = new QLineEdit;
filterPatternLabel = new QLabel(tr("Filter Pattern: "));
filterColumnComboBox = new QComboBox;
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 = new QGridLayout;
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("..."));
}
To copy to clipboard, switch view to plain text mode
baz.h - from this file comes extern functions
{
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);
}
QAbstractItemModel *asd(QObject *parent)
{
QStandardItemModel *model = new QStandardItemModel(0, 3, parent);
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;
}
void dodajwpis(QAbstractItemModel *model, QString wpistyp, QString wpisnazwa, QString wpiszaw, QString wpiskraj)
{
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);
}
To copy to clipboard, switch view to plain text mode
Bookmarks