Segmentation error. Problem with class.

customersAddLayout.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef CUSTOMERLAYOUT_H
#define CUSTOMERLAYOUT_H

#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QGridLayout>
#include <QVBoxLayout>

class CustomerAddLayout : public QWidget {

    Q_OBJECT

public:

    explicit CustomerAddLayout();

public slots:

    QVBoxLayout *returnCustomerLayout();

private:

    QPushButton *addCustomerButton;
    void setCustomerAddLayout();

    QGridLayout *grid;

    QLabel *name;
    QLabel *lastname;
    QLabel *address;
    QLabel *ID;
    QLabel *phoneNr;

    QLineEdit *nameEdit;
    QLineEdit *lastnameEdit;
    QLineEdit *addressEdit;
    QLineEdit *IDedit;
    QLineEdit *phoneNrEdit;
};

#endif // CUSTOMERLAYOUT_H


customersAddLayout.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "customerAddLayout.h"

CustomerAddLayout::CustomerAddLayout() {

    name     = new QLabel("Vardas:",           this);
    lastname = new QLabel("Pavarde:",          this);
    address  = new QLabel("Gyvenamoji vieta:", this);
    ID       = new QLabel("Asmens kodas: ",    this);
    phoneNr  = new QLabel("Tel. numeris:",  this);

    nameEdit     = new QLineEdit(this);
    lastnameEdit = new QLineEdit(this);
    addressEdit  = new QLineEdit(this);
    phoneNrEdit  = new QLineEdit(this);
    IDedit       = new QLineEdit(this);

    addCustomerButton = new QPushButton("Prideti pirkeja", this);

    grid = new QGridLayout();
    setCustomerAddLayout();
}

void CustomerAddLayout::setCustomerAddLayout() {

    grid->addWidget(name, 0, 0);
    grid->addWidget(nameEdit, 0, 1, 1, 10);
    grid->addWidget(lastname, 1, 0);
    grid->addWidget(lastnameEdit, 1, 1, 1, 10);
    grid->addWidget(address, 2, 0);
    grid->addWidget(addressEdit, 2, 1, 1, 10);
    grid->addWidget(ID, 3, 0);
    grid->addWidget(IDedit, 3, 1, 1, 10);
    grid->addWidget(phoneNr, 4, 0);
    grid->addWidget(phoneNrEdit, 4, 1, 1, 10);

    grid->addWidget(addCustomerButton, 6, 9, 1, 2);
}

QVBoxLayout *CustomerAddLayout::returnCustomerLayout() {
    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->addLayout(grid);
    return vbox;
}

Last edited on
Help, please.. bump
Last edited on
I figured it out myself with a hint of a friend, the problem was that I was adding new layout right here:

1
2
3
4
5
QVBoxLayout *CustomerAddLayout::returnCustomerLayout() {
    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->addLayout(grid);
    return vbox;
}


I fixed it like this:
1
2
3
QVBoxLayout *CustomerAddLayout::returnCustomerLayout() {
    return vbox;
}
Last edited on
Damn - I wasnt going to say that - but I found another fix that stopped it crashing - but your fix look better.
Topic archived. No new replies allowed.